Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Check the frequency of an element in Java

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Demo {
	public static void main(String[] args) {
		List<String>list = Arrays.asList("P","Q","R","P","T","P","U","V","W","X","W" );
		int checkOccurrence = Collections.frequency(list, "P");
		System.out.println("Occurrence of P = " + checkOccurrence);
		checkOccurrence = Collections.frequency(list, "W");
		System.out.println("Occurrence of W = " + checkOccurrence);
		checkOccurrence = Collections.frequency(list, "T");
		System.out.println("Occurrence of T = " + checkOccurrence);
	}
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.