there are some duplicate values in ArrayList, how U'll get
that array with out duplicate?
Answer Posted / banti
public void removeDuplicateDataFromArrayList(){
ArrayList<String> al = new ArrayList<>();
al.add("a");
al.add("b");
al.add("c");
al.add("c");
al.add("a");
HashSet<String> hs = new HashSet<>();
hs.addAll(al);
al.clear();
al.addAll(hs);
System.out.println("The ArrayList values are :"+ al);
// Or
System.out.println("ArrayList : ");
for (Object data : al) {
System.out.println(data);
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is a string what operation can be performed out with the help of a string?
Can we create constructor in abstract class ?
How many inner classes can a class have?
What are the topics in core java?
Can we declare a static variable inside a method?
Which is better ascii or unicode?
Is call by reference possible in java?
What is immutability in java?
What are the differences between heap and stack memory in java?
When should I use stringbuffer?
What is a method signature java?
What is the difference between state-based unit testing and interaction-based unit testing?
Does java support function overloading, pointers, structures, unions or linked lists?
Is there is any difference between a scrollbar and a scrollpane?
What is the difference between conversation & casting?