I have large ArrayList of Strings. Each String element of the list is quite large too. I want to count how many times the word "the" appears in each element of the list. My current code only iterates through index 1. How do I make it count for all elements of the array?
public static int counter(List<String> comments) {
for (String comment : comments.subList(1, comments.size() - 1)) {
String a[] = comment.split(" ");
String word = "the";
int count = 0;
for (int j = 0; j < a.length; j++) {
if (word.equals(a[j])) {
count++;
}
}
System.out.println(comment);
return count;
}
System.out.println("sefsfsfseesfeseeeeeeeeeeeeeeeeeeeeeee");
return 0;
}