How to count occurrences of each duplicate element in a list
{a,b,d,c,a,b} ?

Thanks in Advance

Answer Posted / pratiksha

import java.util.*;
class alpha
{
String let;
public alpha(String l)
{
this.let=l;
}
}

public class Duplicateletters
{
public static void main(String []args)
{
int i=0;
String[] letters = {"a", "b", "b", "c" ,"a", "d","a"};
ArrayList<alpha> a = new ArrayList<alpha>();
for(i=0;i<letters.length;i++)
{
a.add(new alpha(letters[i]));
}
String let1=null;
Iterator<alpha> i1 = a.iterator();
while(i1.hasNext())
{
alpha a1 = i1.next();
let1=a1.let;
}
int j=0;
Iterator<alpha> i2 = a.iterator();
while(i2.hasNext())
{

alpha a2 = i2.next();
if(let1==a2.let)
{
j=j+1;
}
}
System.out.println(j);

}
}

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is identifier in java?

782


Who is founder of java?

749


What is the nested interface?

800


Can java inner class be static?

758


What is float in java?

767


what is a thread pool in java and why is it used?

727


Is there a sort function in java?

766


Compare java and python.

764


What is covariant return type?

856


When parseint method can be used?

723


How to check if linked list contains loop in java?

654


What is meant by local variable and instance variable?

821


What is identifier give example?

788


How does java enable high performance?

929


What are the access modifiers available in java?

813