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 string intern in java?
How to sort array in descending order in java?
How can we find the actual size of an object on the heap?
What is a byte string?
What about method local inner classes or local inner classes in java?
How do you sing an Applet ?
what do you mean by stream pipelining in java 8? Explain
Explain the difference between abstract class and interface in java?
What is the equal sign?
Define linked list and its features with signature?
What happens to the Exception object after handling an exception?
What is anti pattern in programming?
Can we have multiple public classes in a java source file?
What is java jit compilers?
Can a class with private constructor be extended?