Java.util.Collections.frequency() in Java with Examples
java.util.Collections.frequency() method is present in java.util.Collections class. It is used to get the frequency of a element present in the specified list of Collection. More formally, it returns the number of elements e in the collection.
public static int frequency(Collection<?> c, Object o) Parameters : c - the collection in which to determine the frequency of o o - the object whose frequency is to be determined Returns : Returns the number of elements in the specified collection equal to the specified object. Throws: NullPointerException - if c is null
How to Quickly get frequency of an element in an array in Java ?
Arrays class in Java doesn’t have frequency method. But we can use Collections.frequency() to get frequency of an element in an array also.
This article is contributed by Gaurav Miglani. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.