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 method reference in java?
What are the features of junit?
How do you clear a method in java?
Why wait(),notify(),notifyAll() methods defined in Object class althought we are using in only threads.
Is main an identifier?
How many bits is a 64 bit byte?
Explain the difference between runnable and callable interface in java?
What is singleton class in java and how can we make a class singleton?
What is a variable and constant?
What does system out println () do?
What are the differences between include directive and include action?
Can a main method be declared final?
What is the symbol for line break?
Can we sort a map in java?
What is math floor in java?