Java.util.Collections.frequency() in Java with Examples Last Updated : 07 Dec, 2018 Comments Improve Suggest changes Like Article Like Report 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. Syntax 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 Java // Java program to demonstrate working of // java.utils.Collections.frequency() import java.util.*; public class FrequencyDemo { public static void main(String[] args) { // Let us create a list of strings List<String> mylist = new ArrayList<String>(); mylist.add("practice"); mylist.add("code"); mylist.add("code"); mylist.add("quiz"); mylist.add("geeksforgeeks"); // Here we are using frequency() method // to get frequency of element "code" int freq = Collections.frequency(mylist, "code"); System.out.println(freq); } } Output: 2 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. Java // Java program to get frequency of an element // with java.utils.Collections.frequency() import java.util.*; public class FrequencyDemo { public static void main(String[] args) { // Let us create an array of integers Integer arr[] = {10, 20, 20, 30, 20, 40, 50}; // Please refer below post for details of asList() // https://www.geeksforgeeks.org/array-class-in-java/ int freq = Collections.frequency(Arrays.asList(arr), 20); System.out.println(freq); } } Output: 3 Comment More infoAdvertise with us Next Article Java.util.Collections.frequency() in Java with Examples G Gaurav Miglani Improve Article Tags : Java Practice Tags : Java Similar Reads Java.util.Collections.frequency() in Java The method is a java.util.Collections class method. It counts the frequency of the specified element in the given list. It override the equals() method to perform the comparison to check if the specified Object and the Object in the list are equal or not. Syntax: public static int frequency(Collecti 2 min read Java.util.Collections.disjoint() Method in java with Examples java.util.Collections.disjoint() method is present in java.util.Collections class. It is used to check whether two specified collections are disjoint or not. More formally, two collections are disjoint if they have no elements in common. Syntax: public static boolean disjoint(Collection<?> c1, 3 min read Collections max() method in Java with Examples max(Collection<? extends T> coll) The max() method of java.util.Collections class is used to return the maximum element of the given collection, according to the natural ordering of its elements. All elements in the collection must implement the Comparable interface. Furthermore, all elements 5 min read Collections fill() method in Java with Examples The fill() method of java.util.Collections class is used to replace all of the elements of the specified list with the specified element. This method runs in linear time. Syntax: public static void fill(List list, T obj) Parameters: This method takes following argument as parameter list - the list t 2 min read Collectors groupingBy() method in Java with Examples The groupingBy() method of Collectors class in Java are used for grouping objects by some property and storing results in a Map instance. In order to use it, we always need to specify a property by which the grouping would be performed. This method provides similar functionality to SQL's GROUP BY cl 2 min read Collections min() method in Java with Examples min(Collection<? extends T> coll) The min() method of java.util.Collections class is used to return the minimum element of the given collection, according to the natural ordering of its elements. All elements in the collection must implement the Comparable interface. Furthermore, all elements 4 min read Collectors toSet() in Java with Examples Collectors toSet() returns a Collector that accumulates the input elements into a new Set. There are no guarantees on the type, mutability, serializability, or thread-safety of the Set returned. This is an unordered Collector i.e, the collection operation does not commit to preserving the encounter 2 min read Collections list() method in Java with Examples The list() method of java.util.Collections class is used to return an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration. This method provides interoperability between legacy APIs that return enumerations and new APIs that requi 2 min read Collections.shuffle() Method in Java with Examples shuffle() method of Collections class as the class name suggests is present in utility package known as java.util that shuffles the elements in the list. There are two ways with which we can use to implement in our programs that are as follows: Using the pre-defined source of randomnessUsing the use 4 min read Collectors toList() method in Java with Examples The toList() method of Collectors Class is a static (class) method. It returns a Collector Interface that gathers the input data onto a new list. This method never guarantees type, mutability, serializability, or thread-safety of the returned list but for more control toCollection(Supplier) method c 2 min read Like