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

What is method reference in java?

565


What are the features of junit?

602


How do you clear a method in java?

544


Why wait(),notify(),notifyAll() methods defined in Object class althought we are using in only threads.

2374


Is main an identifier?

546






How many bits is a 64 bit byte?

537


Explain the difference between runnable and callable interface in java?

588


What is singleton class in java and how can we make a class singleton?

574


What is a variable and constant?

548


What does system out println () do?

561


What are the differences between include directive and include action?

547


Can a main method be declared final?

588


What is the symbol for line break?

612


Can we sort a map in java?

578


What is math floor in java?

475