title: Count occurrences of a given string in an ArrayList
body: <p>I have a list of strings , I browse it and count number of "x" strings as below but the count doesn't print me the expected value:</p>
  
  <pre><code>ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
  
  List&lt;String&gt; strings = table.getValue(); //this gives  ["y","z","d","x","x","d"]
  
  int count = 0;
  for (int i = 0; i &lt; strings.size(); i++) {
      if ((strings.get(i) == "x")) {
          count++;
          list.add(count);
      }
  }
  
  System.out.println(list);
  </code></pre>
  
  <p>this gives <code>[]</code> it should be 2 as I have 2 occurrences of "x"</p>