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 |
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