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 is the static method?

565


How do you call a reference in java?

515


What is a jit compiler?

632


What happens if an exception is not handled in a program?

620


What is a generic code?

524






What are the important methods of java exception class?

569


Which sorting algorithm is best in java?

531


Define immutable object?

575


What are the advantages and disadvantages of object cloning?

566


Define iterator and methods in iterator?

545


How do you reverse a string in java?

574


What is a private class in java?

506


how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? : Java thread

527


What is an escape character in java?

525


What are the 3 types of control structures?

527