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
What are the core java topics?
What do you understand by garbage collection in Java? Can it be forced to run?
What is Java Reflection API? Why it’s so important to have?
Can static method access instance variables ?
How does enum work in java?
Can we cast any other type to boolean type with type casting?
Write a method that will remove given character from the string?
Is it possible to use string in the switch case?
What is square root in java?
Difference between static synchronization vs. Instance synchronization?
Can we execute a program without main() method?
4.1 Supply contracts (in the form of comments specifying pre- and post conditions) for the enqueue() method of the LinkedQueue class given in the Appendix. (2) 4.2 Let Thing be a class which is capable of cloning objects, and consider the code fragment: Thing thing1 = new Thing(); //(1) Thing thing2 = thing1; //(2) Thing thing3 = (Thing) thing1.clone(); //(3) Explain how the objects thing2 and thing3 differ from each other after execution of the statements. (
If I only change the return type, does the method become overloaded?
Define jit compiler?
What is a pointer and does java support pointers?