Results 1 to 9 of 9
Thread: Duplicates in more than two sets
- 12-03-2009, 01:59 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 8
- Rep Power
- 0
Duplicates in more than two sets
Good day...
I have a map which is declared to hold String and TreeSet integer.
like so :
Name : 10 , 20 , 40
Name2 : 12 , 33, 50
Name3: 14, 50, 20
Name4: 20,10,80
..etc
I want to ensure that each name has unique set of integers no duplicates allowed even if the duplicate number is in another name's set..
for two sets I can compare directly and remove duplicates but what is the best way to ensure that there is no duplicates while there are more than two sets ??
Thank you in advance
- 12-03-2009, 02:22 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
Have a look at the Set.removeAll( ... ) method; it returns true if the Set has changed because of the method.
kind regards,
JosLast edited by JosAH; 12-03-2009 at 02:35 PM.
- 12-03-2009, 02:39 PM #3
Member
- Join Date
- Dec 2009
- Posts
- 8
- Rep Power
- 0
JosAh
thanks for your reply ..
If I got it right... the problem still exists I should repeat this multiple times..
someVar.get("Name").removeAll(someVar.get("Name1") );
someVar.get("Name").removeAll(someVar.get("Name2") );
...etc
regards
- 12-03-2009, 02:41 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
- 12-03-2009, 02:48 PM #5
Member
- Join Date
- Dec 2009
- Posts
- 8
- Rep Power
- 0
Thanks for your quick response .. one more question :
suppose I have two tables of these
table 1
Name : 10 , 20 , 40
Name2 : 12 , 33, 50
Name3: 14, 50, 20
Name4: 20,10,80
table2
... etc
How can I ensure that table 2 also doesn't have any duplicates from the first table integer sets ..?
Best Regards
- 12-03-2009, 03:07 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
Take the union of all sets in the first table and use that to removeAll( ... ) for all the sets in the second table. If something is actually removed the intersection of the two tables wasn't empty. If your data survives this test do the first test per table.
kind regards,
Jos
- 12-03-2009, 03:32 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
How are these things being populated?
Wouldn't it be better to have some sort of master set. As you add numbers into the other sets, you add them into the master set first and only add them to these other sets if they didn't already exist in the master.
Something along those lines anyway.
- 12-03-2009, 03:57 PM #8
Member
- Join Date
- Dec 2009
- Posts
- 8
- Rep Power
- 0
They are populated thru a populatemethod(name[], name2[], name3[],name4[])
- 12-03-2009, 04:07 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
How to plot a graph for two sets of variables....
By Megatron in forum New To JavaReplies: 9Last Post: 04-20-2009, 09:20 PM -
Printing the union and instersection of two sets
By Java Tip in forum java.langReplies: 0Last Post: 04-15-2008, 07:35 PM -
No duplicates allowed in Sets
By Java Tip in forum Java TipReplies: 0Last Post: 01-21-2008, 04:33 PM -
Duplicates
By Gambit17 in forum New To JavaReplies: 5Last Post: 11-08-2007, 09:56 AM -
duplicates in iReport
By Heather in forum Advanced JavaReplies: 1Last Post: 07-05-2007, 04:42 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks