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 byte value?
Write a code to create a trigger to call a stored procedure
Can we sort hashset in java?
Why volatile is used in java?
What is a jit compiler?
Similarity and difference between static block and static method ?
Why doesn't the java library use a randomized version of quicksort?
What does main method?
Is object a data type?
How do you create an array in java?
What is annotation in java?
What do you mean by default constructor in java?
Explain tree set and its features?
Is integer a class?
explain different ways of using thread? : Java thread