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
Hey sorry. There is a small correction to the above code
/**
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));
while (index != -1 && index != i) {
al.remove(i);
index = al.lastIndexOf(al.get(i));
}
}
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Give the hierarchy of inputstream and outputstream classes.
How can we create objects if we make the constructor private ?
What is the constructor?
Can we catch more than one exception in a single catch block?
Explain wait(), notify() and notifyall() methods of object class ?
What is Recursion Function?
What does it mean that a class or member is final?
Can java arraylist hold different types?
Can we access the non-final local variable, inside the local inner class?
Is singleton set an interval?
Difference between object instantiation and construction ?
What happens when main () method is declared as private?
What is illegal identifier in java?
If we allocate the memory using 'new' & de-allocated using 'free' then what will happen?
Write a program to find maximum and minimum number in array?