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

Is string is a data type?

0 Answers  


What is a Null object?

1 Answers   Wipro,


Explain about the main() method in java?

0 Answers  


What do you mean by garbage collection used in java?

0 Answers  


Why method overriding is used?

0 Answers  






What is the list interface in java programming?

0 Answers  


What is inner class?what is the use of inner class?where we create the object for inner class? and inner class can extend any class or inner class can implement any interface?

1 Answers   Wipro,


Hi Anyone know the model / questions of the Federal bank sample questions for the post of Specialist Officers - Programmers. Please post if anyone have..

0 Answers  


What is immutable in java?

0 Answers  


Define Multiprogramming and Multiprocessing in java.

0 Answers   Akamai Technologies,


Is it possible to use Semaphore/ Mutex in an Interrupt Handler?

0 Answers   Ciena,


Explain list interface?

0 Answers  


Categories