This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes remove duplicates from an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "remove duplicates from an array" Watch "remove duplicates from an array" New topic
Author

remove duplicates from an array

Pradeep Chauhan
Greenhorn

Joined: Nov 11, 2002
Posts: 10
Hi there,
I have an array, String []
I have to remove duplicates from this array. I can use a temp array.
Could anybody guide me as how will I do this?
_pradeep
Pradeep Chauhan
Greenhorn

Joined: Nov 11, 2002
Posts: 10
my array is 2d, let's say String [i][2] and I have to remove all the duplicates for
String[i][0] and String[i][1].
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Is this homework? Have you tried anything yet? If you've tried something and you're stuck, let us see what you've done and we'll help.
In addition, since this doesn't really pertain to the SCJP certification, I'm moving this to Java in General (Beginner).
Corey


SCJP Tipline, etc.
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

I have to remove duplicates from this array.

Are the duplicates allowed in the first place? If not, a HashSet may be a more appropriate data structure. If you insist on using an array, consider an ArrayList collection.
Eugene.
[ March 31, 2003: Message edited by: Eugene Kononov ]
Pradeep Chauhan
Greenhorn

Joined: Nov 11, 2002
Posts: 10
No Duplicates are not allowed in first place. Actually first place is a key.
Had it been one-dimesional array, I would have used HashSet. I don't know for 2d array.
Could anybody help me as I'm not an experienced guy in java.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451

Had it been one-dimesional array, I would have used HashSet.

What Eugene is getting at is you can put the Strings in a HashSet (or any Set for that matter) and attempting to add a duplicate will have no effect since Sets do not allow duplication.
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: remove duplicates from an array