how to identify duplicate values in arraylist
Answers were Sorted based on User's Feedback
Answer / shrinu nallavelli
arrayList elements are differentiated by their index values
onlu..
Is This Answer Correct ? | 3 Yes | 3 No |
Answer / srikanth m
List<String> list = new ArrayList<String>();
list.add("abc");
list.add("def");
list.add("abc");
HashMap<String, Integer> map = new HashMap<String, Integer>();
for (String str : list) {
Integer c = (Integer) map.get(str);
if (c == null || c == 0) {
map.put(str, 1);
} else {
map.put(str, ++c);
}
}
System.out.println(map);
Is This Answer Correct ? | 0 Yes | 0 No |
How do you clear a list in java?
How do you convert int to char in java?
Why Java is not purely object oriented?
50 Answers Elitecore, Persistent, Reliance, Wipro,
What are predicates in java 8?
What are the benefits of operations in java?
When will we use class loader?
Which Java operator is right associative?
What is class forname used for?
What are teh sub-classes of a component class?
when a servlet sends request for first time it uses the follwing methods a)init b)doget() c)dopost() d)service
what is the use of declaring constructor as private?
5 Answers Cyient, IVY Technologies, Sai Softech, Virtusa,
What is data type in computer?