Count occurrences of a given string in an ArrayList

juranusekt

New Member
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:\[code\]ArrayList<Integer> list = new ArrayList<Integer>();List<String> strings = table.getValue(); //this gives ["y","z","d","x","x","d"]int count = 0;for (int i = 0; i < strings.size(); i++) { if ((strings.get(i) == "x")) { count++; list.add(count); }}System.out.println(list);\[/code\]this gives \[code\][]\[/code\] it should be 2 as I have 2 occurrences of "x"
 
Top