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
How hashmap increases its size in java?
How do you clear an arraylist in java?
What is flush buffer?
What is constant in programming?
What is method in java ?
Why java is considered dynamic?
What is meant by design patterns?
Program to Find the second largest element in an array.
what is singleton in java?
How many types of flags are there?
Which sorting is best in java?
Explain naming conventions for packages?
Is java call by reference?
Can we declare an interface as final?
What is module in project?