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 are the important features of Java 10 release?
Can you use abstract and final both with a method?
Which class is the superclass for all the classes?
How to make object serializable in java?
What are thread local variables?
Can java program run without jre?
Which package is always imported by default?
Is string is a keyword in java?
What is the major difference between linkedlist and arraylist?
What is meant by nested loop?
What is the synonym of string?
Difference between static and dynamic class loading.
Highest level event class of the event-delegation model?
Where is java located?
Can java arraylist hold different types?