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
What is an association?
How do you check whether the list is empty or not in java?
What is the use of inner class?
What is port number in java?
What are examples of modifiers?
Program to Find the second largest element in an array.
What is static variable with example?
Explain about main() method in java ?
Does java runtime require a license?
What is the exact difference in between unicast and multicast object? Where we will use?
What is dynamic binding(late binding)?
What is the difference between the reader/writer class hierarchy and the inputstream/outputstream class hierarchy in java programming?
Can the interface be final?
What is application system?
How does linkedhashmap work in java?