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 are selection structures?
Is void a return type?
What is autoboxing in java?
Explain heap sort?
What does the @override annotation do?
Describe string intern() methodology
What is the use of object and class classes?
Are arrays static in java?
Write a program to search a number in the given list of numbers.
Does string isempty check for null?
Convert a BST into a DLL and DLL to BST in place.
What is the purpose of declaring a variable as final?
Is null or empty java?
What is the purpose of return statement?
What is arrays aslist in java?