3:24 am - Friday April 19, 2019

Java Collections frequency example program

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

Here is a java example program for collections frequency operation in Collection c, Object o. The main function of this method is to get the frequency of an element present in the specified list of Collection.

Here how to do java collections frequencies,

@author:Candid
@discription:Collections Example program for frequency(Collection c, Object o)
**/
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Freq
{
public static void main(String args[])
{
List arrlist = new ArrayList(); //Create object arrlist
arrlist.add("X"); //add x in arrlist
arrlist.add("Y"); //add y in arrlist
arrlist.add("Z"); //add z in arrlist
arrlist.add("G"); //add G in arrlist
arrlist.add("C"); //add c in arrlist
int freq = Collections.frequency(arrlist, "Z"); //To find freq()
System.out.println("Frequency of 'Z' is: "+freq);//to print freq
}
}

Output:
Frequency of ‘Z’ is: 1

BACK

Filed in: Z-A All Java Codes

Comments are closed.