I have a list of lines, I look through it and count the number of lines "x" as shown below, but the count does not display the expected value:
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);
this gives [] , it should be 2 since I have 2 occurrences of "x"
source share