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

How does java enable high performance?

682


What are the differences between abstract class and interface?

502


Justify your answer that you can't define a method inside another method in java, if you can then how?

596


What do you understand by classes in java?

549


Discuss different types of errors that generally occur while programming.

567






What is difference between iterator access and index access?

638


How do I get the | symbol on my keyboard?

585


Explain the inheritance?

565


What is constructor chaining and how is it achieved in java?

564


Can we compare two strings in java?

552


What does main method?

550


What purpose do the keywords final, finally, and finalize fulfill?

604


What is a string what operation can be performed out with the help of a string?

501


What is the use of a conditional inclusion statement in Java ?

578


What is the difference between multitasking and multithreading in Java

709