| Author |
copy a list in a set
|
Marco Vanoli
Ranch Hand
Joined: Jan 12, 2005
Posts: 99
|
|
it is possible to copy one list in a set? as: List l = (List) x.getset(); My compiler give error.. is there a quickest way to not do a loop with iterator for addin every one set elements to the list? tnKs
|
bye, <br />Marco
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
You can't just cast a Set to type List because neither is a subtype of the other. However, you should be able to pass the Set instance to the constructor of a List (where it's upcast to Collection)...
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
|
|
You can also create a Set from a List with the correct constructor: Set mySet = new HashSet(myList); Layne
|
Java API Documentation
The Java Tutorial
|
 |
 |
|
|
subject: copy a list in a set
|
|
|