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 are decalarations?

0 Answers  


What are the access modifiers available in java?

0 Answers  


Can we access private data outside of the class directly in java programming language? Why There is no runtime checking in java, which leads to access the private data directly outside of a class?

5 Answers   Google,


Can static methods be overridden?

5 Answers   Bravura Solutions,


what is a thread pool in java and why is it used?

0 Answers  






What are features of java?

0 Answers  


what is default layout of JFrame class?

6 Answers  


Is void a data type?

0 Answers  


What is the purpose of using the java bean?

0 Answers  


What is instance synchronization?

0 Answers  


Is the empty set a singleton?

0 Answers  


How to override equals() and hashCode() method in java?

1 Answers   Wipro,


Categories