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

Which is bigger float or double?

522


What is internal iteration in java se 8?

631


Explain what is Marker interface?

622


What is rmi and steps involved in developing an rmi object?

572


What is difference between ++ I and I ++ in java?

535






What is the difference between a vector & an array list?

677


What are constructors in java?

574


What is assembly language?

553


Explain about procedural programming language or structured programming language and its features?

550


Why set do not allow duplicates in java?

584


Can you give few examples of final classes defined in java api?

567


What is difference between path and classpath in java?

487


What is the importance of hashcode() and equals() methods?

585


How to access arraylist elements in java?

495


Which package is imported by default?

637