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 |
What is instance synchronization?
Is nullpointerexception checked or unchecked?
what is difference between validation.xml & validation rules.xml?
Which variable is the independent variable?
How many bits is a string in java?
In Java list the methods that can be overridden?
What is the difference between the jdk 1.02 event model and the event-delegation model introduced with jdk 1.1?
What is double parsedouble in java?
What is subsequence of a string?
Distinguish between a predicate and a function?
What do you mean by checked exceptions?
What is the life-cycle of an object?