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

How do you clear a list in java?

0 Answers  


How do you convert int to char in java?

0 Answers  


Why Java is not purely object oriented?

50 Answers   Elitecore, Persistent, Reliance, Wipro,


What are predicates in java 8?

0 Answers  


What are the benefits of operations in java?

0 Answers  






When will we use class loader?

2 Answers  


Which Java operator is right associative?

3 Answers  


What is class forname used for?

0 Answers  


What are teh sub-classes of a component class?

2 Answers  


when a servlet sends request for first time it uses the follwing methods a)init b)doget() c)dopost() d)service

4 Answers   Accenture,


what is the use of declaring constructor as private?

5 Answers   Cyient, IVY Technologies, Sai Softech, Virtusa,


What is data type in computer?

0 Answers  


Categories