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 does i ++ mean in Java?

953


What is anagram word?

997


What is method overloading in java ?

1087


What is implicit object in java?

1079


What is the differences between c++ and java? Explain

1045


Why wait(),notify(),notifyAll() methods defined in Object class althought we are using in only threads.

2820


In the below example, how many string objects are created?

1047


What is the difference between a static and a non-static inner class in java programming?

1072


What is preparedstatement in java?

1047


What is a constructor overloading in java?

1039


what is daemon thread and which method is used to create the daemon thread? : Java thread

972


How does a for loop work?

988


What is advantage of java?

1025


How do constructors use this() and super()?

1120


What happens when main () method is declared as private?

1145