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
What is the static method?
How do you call a reference in java?
What is a jit compiler?
What happens if an exception is not handled in a program?
What is a generic code?
What are the important methods of java exception class?
Which sorting algorithm is best in java?
Define immutable object?
What are the advantages and disadvantages of object cloning?
Define iterator and methods in iterator?
How do you reverse a string in java?
What is a private class in java?
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
What is an escape character in java?
What are the 3 types of control structures?