I can’t understand how to use it
Have you read the API for that method? Does it look like it would be of any use?
If you have any questions about the API
doc for the method, copy the text of the API doc and paste it here with your questions.
One issue I see with the code is that the value returned by the frequency method is not saved.
Another issue is the number of passes over the list your technique requires.
Another approach is to use a Map<String, Counter> where the key is the String from the list and Counter holds the count of the number of times it was found in the list.