Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is final, finally, finalize?

1036


What is "this" keyword in java? Explain

1058


What does flag mean in java?

980


List any five features of java?

974


Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.

1005


Can a class be private or protected in java?

1010


What is the purpose of interface?

958


When will we use them?

987


What is the return type of the main method?

994


How do you remove an element from an arraylist in java?

954


What is the difference between abstract classes and interfaces?

977


Is 0 true or is 1 true?

911


What is a condition in java?

944


Can a class be private in java?

947


What is double data type?

901