Java Collections frequency() MethodThe 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 1Test it NowOutput: List of elements: [Java, COBOL, Java, C++, Java] Frequency of the Word: 3 Example 2Test it NowOutput: List of elements: [1, 2, 1, 3, 2, 3, 4] Count all with frequency: 1: 2 2: 2 3: 2 4: 1 Example 3Test it NowOutput: Frequency of 20 is: 4 Next TopicJava Collections Class |
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