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

Thanks in Advance

Answer Posted / lal ajith kumara

Since java.Util.Set is not allowing duplicates u can use it

String[] letters = {"a", "b", "b", "c" ,"a", "d","a"};
Set duplicateTester = new HashSet<String>();
for(int i = 0; i<letters.length;i++){
if(true == duplicateTester.add(letters[i])){
System.out.println("true>>"+letters[i]);

}else{
System.out.println("false>>"+letters[i]);
}

}

Is This Answer Correct ?    7 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we use return in constructor?

574


what is server side caching?

1695


What is a function in programming?

646


Why string is called as immutable?

611


What is the difference between a break statement and a continue statement?

680






Explain what is Marker interface?

699


What is the point of polymorphism java?

627


How does remove work in java?

604


Is set ordered?

632


what is difference betweem home interface and remote interface?

2211


What are voids?

616


What is a boolean output?

610


What are constants?

687


How do you convert bytes to character in java?

621


How are the elements of a gridbaglayout organized in java programming?

630