How to read an element in an array and see if it matches with a target string despite double letters
<p>so I'm trying to find the amount of times a String is present in an array. So if I had an array of {AB, ABBBB, AAAABBB, AC} and I had a target String of AB, the frequency of the String AB would be 3 in the array. The program would disregard the repeating ABBBB and AAAABBBB and just read these element as AB. I have my code changing the duplicated sequence into a non-repeating sequence and then comparing that to the target with an if statement, but it's not working and I'm not sure why. `It is just returning back a zero value, when there should be a number.</p>

<p>This is the code:</p>

<pre><code>public static int findFreqWithMutations (String target, String [] arr) {

    int count=0;
        for (String s:arr) {
            String ans= "";
            for (int i=0; i&lt;s.length()-1; i++) {

                if (s.charAt(i) != s.charAt(i+1)) {
                 ans= ans + s.charAt(i);
                }
            }
        if (ans == target) {
            count++;
            }
        }
        return count;
     }
            `
</code></pre>