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


Please Help Members By Posting Answers For Below Questions

Is ++ operator is thread safe in java?

706


What is java autoboxing?

733


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

766


What is the difference between access specifiers and access modifiers in java?

853


Explain how to convert any java object into byte array.

758


How to sort array in descending order in java?

727


Can a method inside a interface be declared as final?

732


What is private public protected in java?

813


Can I uninstall java?

805


What are controls and their different types in awt?

840


How do I print a “?

774


What is a method in programming?

882


What are the main uses of java?

764


Can we increase array size dynamically in java?

721


Explain the difference between association, aggregation and inheritance relationships.

822