title: comparing string arrays in java
body: <p>I am working on a simple Java program where we have sorted string array named <strong><em>arr</em></strong>
  I am trying to compare two adjacent string and calculate frequency for each string present in that array</p>
  
  <pre><code>for(j1=0;j1&lt;arr.length;j1++){
      if(j1+1 &lt; arr.length){ // To prevent arrayOutofBoundsException
           if(arr[j1].equals(arr[j1+1])){
                counter++;
           }
           else {
                System.out.println(arr[j1]+" "+counter);
                counter=1;
           }
  </code></pre>
  
  <p>But it's not working right , what's wrong ?
  edit:problem is not in comparing , it's not calculating frequency as desired</p>