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 will you call an Applet using Java Script Function?
How do you use wildcards?
What is the difference between access specifiers and access modifiers in java? 16
What is logical variable?
What do you mean by local variable and instance variable?
Can I extend singleton class in java?
Can we increase array size dynamically in java?
How many types of the indexof method are there for strings?
How we can execute any code even before main method?
Can we have two methods in a class with the same name?
What is method overloading in java ?
How will you get the platform dependent values like line separator, path separator, etc., ?
Is char a method in java?
What is object cloning in Java?
What is a ternary operator in java?