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.
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java.util.concurrent.RecursiveAction class in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java.util.concurrent.Phaser class in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java.util.BitSet class methods in Java with Examples | Set 2
- Java.util.BitSet class in Java with Examples | Set 1