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
Click to Enlarge