hi forum,
i am using an arraylist for storing a list of objects.i dont want the objects in the list to be ordered but the list should be duplicate free.how can i achieve this.plz help quickly.provide source code if possible.thanks in advance.
Dark Master
0
Newbie Poster
Recommended Answers
Jump to PostA quick and dirty way of doing it would be to create a new ArrayList (arrList2), use a loop to read each object in the original ArrayList (arrList1), use the indexOf method to check arrList2 for the presence of the object that you are checking, add the object to arrList2 …
Jump to PostIf you don't want duplicates, why not use a Set. Like the HashSet. A Set enforces no duplicates.
For further information on all Java Collections, please read:
http://java.sun.com/docs/books/tutorial/collections/index.html
Jump to PostThere is also a contains(Object o) method on List. So, you could check to see if the object is in the ArrayList before adding the Object.
Or you could extend ArrayList with your own class that checks to see if Object is present in the ArrayList using the contains …
All 9 Replies
chrisbliss18
26
Posting Shark
Kate Albany
0
Junior Poster in Training
hooknc
1
Posting Whiz in Training
server_crash
64
Postaholic
jwenting
1,889
duckman
Team Colleague
Dark Master
0
Newbie Poster
jwenting
1,889
duckman
Team Colleague
pnr.nagi@gmail.
-2
Newbie Poster
jwenting
commented:
thread hijacking zombie master
-2
jwenting
1,889
duckman
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.