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

When should you make a function static?

927


What is blank final variable?

1012


What do you mean by constructor?

923


What is the difference between comparison done by equals method and == operator?

976


What is constructor in java ?

1116


how to handle exceptions in ejb?

2259


Why is string builder not thread safe?

1013


Explain some best practices you would apply while using collection in java?

980


What happens when a thread cannot acquire a lock on an object in java programming?

949


What is a singleton class in Java?

981


How to overcome the exception object reference not set to an instance of object?

1098


What is the java project architecture?

2185


What is the purpose of the strictfp keyword?

1109


How many bits is a word?

955


How many types of design patterns are there?

1043