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 <> used for in java?
What is main method?
Is singleton set an interval?
What is a line break?
when to use ArrayList and when to use HashMap in webApplication.
What is ph and buffers?
What is the purpose of void?
Why are pointers not secure?
How does compareto work in java?
What is compiler and what its output.
What is string pool in java?
Does java vector allow null?
What is a stack class in java ?
Can we define private and protected modifiers for the members in interfaces?
Which sorting is best in java?