Forums Register Login

remove duplicates from an array

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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].
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 


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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 


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
Listen. That's my theme music. That's how I know I'm a super hero. That, and this tiny ad told me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1018 times.
Similar Threads
How do you remove duplicate Point Objects in an array?
Remove duplicates from char array with O(n) complexity
inserting repeated values in primary key field
removing duplicates in array ...?????
removing duplicates usig set
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:20:19.