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 does i ++ mean in Java?
What is anagram word?
What is method overloading in java ?
What is implicit object in java?
What is the differences between c++ and java? Explain
Why wait(),notify(),notifyAll() methods defined in Object class althought we are using in only threads.
In the below example, how many string objects are created?
What is the difference between a static and a non-static inner class in java programming?
What is preparedstatement in java?
What is a constructor overloading in java?
what is daemon thread and which method is used to create the daemon thread? : Java thread
How does a for loop work?
What is advantage of java?
How do constructors use this() and super()?
What happens when main () method is declared as private?