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
Is ++ operator is thread safe in java?
What is java autoboxing?
Is it possible to use Semaphore/ Mutex in an Interrupt Handler?
What is the difference between access specifiers and access modifiers in java?
Explain how to convert any java object into byte array.
How to sort array in descending order in java?
Can a method inside a interface be declared as final?
What is private public protected in java?
Can I uninstall java?
What are controls and their different types in awt?
How do I print a “?
What is a method in programming?
What are the main uses of java?
Can we increase array size dynamically in java?
Explain the difference between association, aggregation and inheritance relationships.