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
Is string passed by reference in java?
Explain the difference between comparator and comparable in java?
Tell me a few examples of final classes defined in Java API?
What is a java lambda expression?
How many bytes are there?
How would you format a date in java? I.e. In the ddmmyyy format?
Is array passed by reference in java?
Which class cannot be a subclass in java?
Give an example of use of pointers in java class.
What’s the difference between the methods sleep() and wait()?
What is meant by collection in java?
Can Exception handling we can handle multiple catch blocks?
How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters?
What is lambda expression in java?
What are the wrapped, classes?