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 / gopal

Guys lets keep it simple:

/**
Remove duplicates from ArrayList<String> without using Set
*/
private static void removeDuplicates (ArrayList<String> al) {
for (int i=0;i <al.size(); i++) {
int index = al.lastIndexOf(al.get(i));
if (index != -1 && index != i) {
al.remove(i);
index = al.lastIndexOf(al.get(i));
}
}
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is string passed by reference in java?

541


Explain the difference between comparator and comparable in java?

479


Tell me a few examples of final classes defined in Java API?

556


What is a java lambda expression?

545


How many bytes are there?

534






How would you format a date in java? I.e. In the ddmmyyy format?

761


Is array passed by reference in java?

571


Which class cannot be a subclass in java?

535


Give an example of use of pointers in java class.

556


What’s the difference between the methods sleep() and wait()?

534


What is meant by collection in java?

537


Can Exception handling we can handle multiple catch blocks?

637


How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters?

577


What is lambda expression in java?

533


What are the wrapped, classes?

591