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.
LVL 1
meow00Asked:
Who is Participating?
 
objectsCommented:
you couls also use the List's containsAll() method
0
 
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
objectsCommented:
Sets are for containing uniqueue elements, ie. no duplicates

what is it u are trying to achieve?
0
 
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
 
dextCommented:
Add a new class with weight value
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.