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

What is an association?

764


How do you check whether the list is empty or not in java?

730


What is the use of inner class?

759


What is port number in java?

795


What are examples of modifiers?

721


Program to Find the second largest element in an array.

815


What is static variable with example?

766


Explain about main() method in java ?

798


Does java runtime require a license?

772


What is the exact difference in between unicast and multicast object? Where we will use?

781


What is dynamic binding(late binding)?

795


What is the difference between the reader/writer class hierarchy and the inputstream/outputstream class hierarchy in java programming?

832


Can the interface be final?

764


What is application system?

690


How does linkedhashmap work in java?

697