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 difference between ++ I and I ++ in java?
How do you write a conditional statement?
Hi i am creating desktop application in that i want calling to mobile number. i have java telephone api (JTAPI) but i dont understand how it configure & use plese help me
What is nested class?
If try block is successfully executed, Then Is Finally block executed?
How will you serialize a singleton class without violating singleton pattern?
What do you understand by abstract classes?
What is the purpose of skeleton and stub?
What are locale settings?
Can we clone singleton class in java?
What is Java Reflection API? Why it’s so important to have?
Which collections are thread safe in java?
What is the purpose of void class?
What is multi-catch block in java?
What are the benefits of operations?