• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

multi elements in a set.

Hello experts,

    Can I have one elements to appear several times in a set ? if not, how do I do it ?

 thanks.
0
meow00
Asked:
meow00
2 Solutions
 
CEHJCommented:
No - use a LIst
0
 
objectsCommented:
not if the elements are equals

you need to use a different collection, such as a List
0
 
objectsCommented:
Sets are for containing uniqueue elements, ie. no duplicates

what is it u are trying to achieve?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
If you see here, it explains what a Set is used for

http://java.sun.com/docs/books/tutorial/collections/interfaces/set.html

Have a look thru here to determine the type of Collection that best suits your needs:

http://java.sun.com/docs/books/tutorial/collections/interfaces/index.html
0
 
meow00Author Commented:
So I have two collections:

 list1 = "A", "A", "B", "C", "C"
 and
 list2 = "C", "A", "A", "C","B"

 if the order I added to the list are different ...
 how do I check if they are the same ( ps. I need the above to list to be EQUAL) ... can list do that ?

 thanks.
0
 
CEHJCommented:
sort them first then apply list1.equals(list2)
0
 
objectsCommented:
use an ArrayList and first sort them
0
 
objectsCommented:
Collections.sort(list1);
Collections.sort(list2);
if (list1.equals(list2))
{
    ...
0
 
objectsCommented:
you couls also use the List's containsAll() method
0
 
dextCommented:
Add a new class with weight value
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now