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
When should you make a function static?
What is blank final variable?
What do you mean by constructor?
What is the difference between comparison done by equals method and == operator?
What is constructor in java ?
how to handle exceptions in ejb?
Why is string builder not thread safe?
Explain some best practices you would apply while using collection in java?
What happens when a thread cannot acquire a lock on an object in java programming?
What is a singleton class in Java?
How to overcome the exception object reference not set to an instance of object?
What is the java project architecture?
What is the purpose of the strictfp keyword?
How many bits is a word?
How many types of design patterns are there?