how to identify duplicate values in arraylist

Answers were Sorted based on User's Feedback



how to identify duplicate values in arraylist..

Answer / shrinu nallavelli

arrayList elements are differentiated by their index values
onlu..

Is This Answer Correct ?    3 Yes 3 No

how to identify duplicate values in arraylist..

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

Post New Answer

More Core Java Interview Questions

What is the difference between call by reference and call by pointer?

0 Answers  


What does singleton class mean?

0 Answers  


What is continuity of a function?

0 Answers  


what are abstract functions?

0 Answers  


what are depricated methods ?

5 Answers   Satyam,


Can we overload the main() method?

0 Answers  


What is static and a non-static inner class?

3 Answers  


What is int argc char * argv?

0 Answers  


How big is a 64 bit float?

0 Answers  


What is the difference between array and array list in java?

0 Answers  


what is the need of the Ajax?

5 Answers   iFlex,


I have a String s = java; What is the output when I say s.replaceAll('j', 'k'); Also what is the value of s after replacing?

8 Answers   KPIT,


Categories