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


Please Help Members By Posting Answers For Below Questions

What is string in java is it a data type?

723


What exactly is a .class file?

787


What is the benefit of inner / nested classes ?

704


What is the difference between logical data independence and physical data independence?

755


Which class represents the socket that both the client and server use to communicate with each other?

778


List out five keywords related to exception handling ?

779


When to use runnable interface vs thread class in java?

729


What differences exist between iterator and listiterator?

790


What is collections framework?

824


What are the drawbacks of reflection?

750


Why static functions are used?

781


How do you escape a string?

699


Which class is used by server applications to obtain a port and listen for client requests?

698


Is void a data type in java?

715


Why we do exception handling in java and how many types of exceptions are there?

746