I have a Arraylist object, it has duplecate values also. Now
question is i want delete duplecate data in that objet with
out using Set?
Answer Posted / srivatsava
import java.util.*;
public class ArrayListDuplicateValueDeleteExample {
/**
* ArraList Duplicate values removed without using Set.
*/
public static void main(String[] args) {
ArrayListDuplicateValueDeleteExample obj = new ArrayListDuplicateValueDeleteExample();
ArrayList al = new ArrayList();
ArrayList al1 = new ArrayList();
al.add("A");
al.add("B");
al.add("B");
al.add("B");
al.add("B");
al.add("C");
al.add("A");
al.add("A");
al.add("A");
al.add("A");
al.add("A");
System.out.println("Size of the array - "+al.size());
System.out.println("ArrayList Values with Duplicate - "+al);
for(int i=0;i<al.size();i++){
if(al.contains(al.get(i))){
if (al1.contains(al.get(i))){
}else {
al1.add(al.get(i));
}
}
}
System.out.println("New ArrayList Values without Duplicate - "+al1);
}
}
| Is This Answer Correct ? | 8 Yes | 0 No |
Post New Answer View All Answers
What is an 8 bit word?
Which collection is ordered in java?
What are the major advantages of internal iteration over external iteration?
What is the difference between declaration and definition in java?
How can you write a loop indefinitely in java programming?
What is your platform?s default character encoding and how to know this?
Can we pass a primitive type by reference in java? How
What is static and final keyword in java?
I want to re-reach and use an object once it has been garbage collected. Define how it’s possible?
Difference between vector and arraylist.
What is the method overriding?
What are the methods to rectify ambiguities in the interfaces in JAVA?
What is a Presistent Object?
Can we create more than one object singleton class?
Explain about object oriented programming and its features?