Java Collections frequency() Method21 Mar 2025 | 2 min read The frequency() method of Java Collections class is used to get the number of elements in the specified collection equal to the specified object. SyntaxFollowing is the declaration of frequency() method: Parameter
ReturnsThe frequency() method returns the number of elements in the collections c equal to the specified object obj. ExceptionsNullPointerException- This exception will be thrown if collection c is null. Compatibility VersionJava 1.5 and above Example 1Output: List of elements: [Java, COBOL, Java, C++, Java] Frequency of the Word: 3 Example 2Output: List of elements: [1, 2, 1, 3, 2, 3, 4] Count all with frequency: 1: 2 2: 2 3: 2 4: 1 Example 3Output: Frequency of 20 is: 4 Next TopicJava Collections Class |
Java Collections Method The method of Java Collections class is used to get an unmodifiable view of the specified set. Syntax Following is the declaration of method: public static <T> Set<T> unmodifiableSet(Set<? extends T> s) Parameter Parameter Description Required/Optional s It is the set for which an unmodifiable view is to be...
2 min read
Java Collections Method The method of Java Collections class is used to reverse the order of the elements in the specified list. Syntax Following is the declaration of method: public static void reverse(List<?> list) Parameter Parameter Description Required/Optional list It is the list whose elements are to be reversed. Required Returns The method does...
2 min read
Java Collections Method The method of Java Collections class is used to check whether two specified collections are disjoint or not. It returns true if the two specified collections have no elements in common. Syntax Following is the declaration of method: public static boolean disjoint(Collection<?> c1,...
3 min read
Java Collections Method The is an inbuilt method of Java Collections class which returns the position of the object in a sorted list. There are two different types of Java collections method which can be differentiated depending on its parameter. These are: Java Collections binarySearch(List<?...
5 min read
Java Collections Method The is a method of Java Collections class which returns a dynamically typesafe view of the specified collection. If an element inserted of the wrong type, it will result in an immediate ClassCastException. Syntax Following is the declaration of method: public static <E>...
2 min read
Java Collections Method The is an inbuilt method of Java Collections class. This method is used to get a dynamically typesafe view of the specified sorted map. Syntax Following is the declaration of method: public static <K,V> SortedMap<K,V> checkedSortedMap(SortedMap<K,V> m, Class<K> keyType, Class<V> valueType) Parameter Parameter Description Required/Optional m It is the...
3 min read
Java Collections Method The method of Java Collections class is used to get a synchronized (thread-safe) map backed by the specified map. Syntax Following is the declaration of method: public static <K,V> Map<K,V> synchronizedMap(Map<K,V> m) Parameter Parameter Description Required/Optional m It is the map which will be wrapped in a synchronized map. Required Returns The...
2 min read
Java Collections Method The method of Java Collections class copies all of the elements from one list into another list. In this method, the size of the destination list must be greater than or equal to the size of the source list. Syntax Following is the...
3 min read
Java Collections Method The method of Java Collections class is used to get an immutable list consisting of n copies of the specified object. Syntax Following is the declaration of method: public static <T> List<T> nCopies(int n, T o) Parameter Parameter Description Required/Optional n It is the number of elements in the...
2 min read
Java Collections Method The method of Java Collections class is used to swap the elements at the specified positions in the specified list. Syntax Following is the declaration of method: public static void swap(List<?> list, int i, int j) Parameter Parameter Description Required/Optional list It is the list in which we will...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India