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

What do you mean by a JVM?

570


Does java support multiple inheritances?

558


Enlist diffrent types of inheritance supported by java?

489


What is the use of java?

530


Is there a way to increase the size of an array after its declaration?

604






How can an exception be thrown manually by a programmer?

515


Name few java 8 annotations ?

569


What is an example of a conditional statement?

568


How will you serialize a singleton class without violating singleton pattern?

1526


What are thread local variables?

556


Can we use catch statement for checked exceptions when there is no chance of raising exception in our code?

592


What is contract between hashcode and equal method?

574


If I only change the return type, does the method become overloaded?

541


Is sizeof a preprocessor?

542


What is array pointers ?

607