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
Can you instantiate the math class?
What is character in data type?
What is port number in java?
Explain the scope of a variable.
What is get () in java?
Is java still necessary?
What happens when you invoke a thread’s interrupt method while it is sleeping or waiting?
What is a variable in java?
How to display all the prime numbers between 1 and n (n is the number, get the input from user)
What is the difference between and ?
How do you clear a list in java?
What is the difference between import java.util.date and java .util?
Can arraylist contain null values?
What is unicode in java?
Is space a char?