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

How do you square a number?

570


What are desktop procedures?

554


What is an empirical question?

533


What is the use of arraylist class in java?

542


Can we use String with switch case?

657






What is difference between path and classpath?

552


What is the difference between superclass and subclass?

536


What advantage do java's layout managers provide over traditional windowing systems?

536


Why do we use bufferedreader?

524


Explain about assignment statement?

589


What is an object in java?

550


What are basic keywords?

549


Why constructor has no return type?

632


What is a parameter example?

518


What is the difference between conversation & casting?

564