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
Compare overloading and overriding?
How we can execute any code even before main method?
What is a list in java?
How many characters is 2 bytes?
What are the special characters?
Explain an algorithm to find depth of a binary tree.
What is a wrapper method?
What is the instance of an object?
What about interthread communication and how it takes place in java?
What is the applet security manager, and what does it provide?
Why spring singleton is not thread safe?
What is a treeset in java?
How does a for loop work?
Can we have this () and super () together?
What is the benefit of inner / nested classes ?