LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-11-2003, 02:44 PM   #1
ksgill
Senior Member
 
Registered: Apr 2003
Location: Toronto, Canada
Distribution: Ubuntu Jaunty (9.04)
Posts: 1,044

Rep: Reputation: 45
Java ArrayList question


How can I remove duplicate entries from an ArrayList and make a new ArrayList with non-duplicate objects? Language is Java.
thanks
 
Old 10-11-2003, 03:14 PM   #2
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
I don't think there automatic way to remove duplicates, but someone may know otherwise

I'd go through each item and save it in a temp, then use the get indexOf(temp) to get the first index number and compare it to lastIndexOf(temp), if they don't match remove the lastIndexOf one, keep doing until indexOf(temp)==lastIndexOf(temp).

Then
myOldArrayList.trimToSize()

and

ArrayList myNewArrayList=new ArrayList(myOldArrayList);

Just the way I'd go about it...

Last edited by Looking_Lost; 10-11-2003 at 03:15 PM.
 
Old 10-12-2003, 07:54 AM   #3
ksgill
Senior Member
 
Registered: Apr 2003
Location: Toronto, Canada
Distribution: Ubuntu Jaunty (9.04)
Posts: 1,044

Original Poster
Rep: Reputation: 45
thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Question k1ll3r_x Programming 2 08-20-2005 08:10 PM
java question zaicheke Programming 5 02-15-2005 12:40 PM
Java Question k1ll3r_x Programming 3 11-13-2004 04:27 AM
ArrayList question (Java) ksgill Programming 5 10-14-2003 02:00 PM
java question TommyD Linux - Newbie 4 07-19-2003 04:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration