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 io stream in java?

507


When will you define a method as static?

546


Why inputstreamreader is used in java?

539


How do you make a thread in java?

622


What are advantages of using Java?s layout managers than windowing systems?

1851






What do you understand by overloading and overriding in java?

535


What is the locale class in java programming?

525


How will you call an Applet using Java Script Function?

536


What are heap memory and stack memory and what are memory tables.

505


Can a method be static?

517


What are the main uses of the super keyword?

547


Can set contain duplicates?

538


What is multithreading in java?

539


Explain about assignment statement?

590


How to pass arraylist to stored procedure in java?

536