Determine which Java language keywords the file contains

I only googled contains, but for some reason it doesn't work.. apparently I'm doing something wrong

keyWords - ArrayList<String>

sortingList also, as I understand it, you need to somehow compare all the words in the file with the list of my words, and how even does not reach

for (int i = 0; i < 50; i++) {
    if (sortingList.get(index).contains(keyWords.get(i))) {
        counter++;              
    }
}

The answer below helped, but now the problem is with repeated words. they are not taken into account

for (String st : keyWords) {
                for (String g : sortingList) {
                    if (st.contains(g) && g.length() > 1) {

                        sortedList.add(g);
                        counter++;
                    }
                }
            }
Author: psyclr, 2015-11-05

1 answers

To be honest, I didn't quite understand the question. Do you want to increase the counter for each word match? If so, it is better to use the for-each loop and do it like this.

for (String s : keyWords) {
    for (String g :  sortingList) { 
        if (s.contains(g)) { 
            counter++;
        }
    }       
}
 4
Author: Zawarudo, 2015-11-06 11:57:59