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
What is final, finally, finalize?
What is "this" keyword in java? Explain
What does flag mean in java?
List any five features of java?
Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.
Can a class be private or protected in java?
What is the purpose of interface?
When will we use them?
What is the return type of the main method?
How do you remove an element from an arraylist in java?
What is the difference between abstract classes and interfaces?
Is 0 true or is 1 true?
What is a condition in java?
Can a class be private in java?
What is double data type?