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


Please Help Members By Posting Answers For Below Questions

What is string subsequence method?

634


Can we access instance variables within static methods ?

573


How do you delete a list in java?

536


What is null data type?

538


What is abstract class? Explain

599






How can we make sure main() is the last thread to finish in java program?

675


What are different types of expressions?

556


Why do we use return statement?

545


How to add menushortcut to menu item?

567


What is the super void?

463


What are access specifiers in java ?

590


How do you compare two objects?

524


What is the difference between the final method and abstract method?

542


What are the different types of inner classes?

536


What are the different data types in java?

535