Determine which Java language keywords a file contains

Question:

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

keyWords - ArrayList<String>

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

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

The answer below helped, but now there is a problem with duplicate words. they are not counted

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

                        sortedList.add(g);
                        counter++;
                    }
                }
            }

Answer:

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

for (String s : keyWords) {
    for (String g :  sortingList) { 
        if (s.contains(g)) { 
            counter++;
        }
    }       
}
Scroll to Top