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

How will you call an Applet using Java Script Function?

540


How do you use wildcards?

528


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

534


What is logical variable?

502


What do you mean by local variable and instance variable?

508






Can I extend singleton class in java?

618


Can we increase array size dynamically in java?

498


How many types of the indexof method are there for strings?

485


How we can execute any code even before main method?

549


Can we have two methods in a class with the same name?

576


What is method overloading in java ?

554


How will you get the platform dependent values like line separator, path separator, etc., ?

575


Is char a method in java?

508


What is object cloning in Java?

629


What is a ternary operator in java?

528