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 do you mean by a JVM?
Does java support multiple inheritances?
Enlist diffrent types of inheritance supported by java?
What is the use of java?
Is there a way to increase the size of an array after its declaration?
How can an exception be thrown manually by a programmer?
Name few java 8 annotations ?
What is an example of a conditional statement?
How will you serialize a singleton class without violating singleton pattern?
What are thread local variables?
Can we use catch statement for checked exceptions when there is no chance of raising exception in our code?
What is contract between hashcode and equal method?
If I only change the return type, does the method become overloaded?
Is sizeof a preprocessor?
What is array pointers ?