Articles → Java → Collections.Frequency() Function In Java

Collections.Frequency() Function In Java






Purpose





Syntax


Collections.frequency(collection, element)



Example


import java.util.ArrayList;
import java.util.Collections;


public class TestClass {

    public static void main(String[] args) {

        ArrayList < String > list = new ArrayList < String > ();
        list.add("Test1");
        list.add("Test2");
        list.add("Test1");
        System.out.println(Collections.frequency(list, "Test1"));
    }
}



Output


Picture showing the output of the Collections.frequency() function in Java
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Friday, March 24, 2017

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250