Articles → Java → Collections.frequency() function in Java

Collections.frequency() function in Java






Purpose





Syntax


Collections.frequency(collection, element)



Example


package com.firstapp;


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



Click to Enlarge


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250