| Author |
turn a Set into a indexed List?
|
Holmes Wong
Ranch Hand
Joined: Feb 18, 2002
Posts: 163
|
|
Hi, I need to use a list (or collection) to display data on jsp page. Is there any fats way to trun a Set into an indexed Collection or List? (Can get individual element using get(index)) thanks,
|
 |
Phil Chuang
Ranch Hand
Joined: Feb 15, 2003
Posts: 251
|
|
Since a Set is a Collection, you should be able to do this: But instead of doing all that, why don't you just use an iterator? [ October 07, 2003: Message edited by: Phil Chuang ]
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
List list = new ArrayList(set); The order of the list will be whatever order the set had. For a TreeSet, this means either natural order, or order determined by the Comparator; for HashSet, well... just pretend it's random. (HashSet order is based on hashCode() and capacity, but the exact algorithm is not specified, so it's best to make no assumptions.)
|
"I'm not back." - Bill Harding, Twister
|
 |
Holmes Wong
Ranch Hand
Joined: Feb 18, 2002
Posts: 163
|
|
thanks, Jim. This may be what I want. I will try it out. QUOTE]Originally posted by Jim Yingst: List list = new ArrayList(set); The order of the list will be whatever order the set had. For a TreeSet, this means either natural order, or order determined by the Comparator; for HashSet, well... just pretend it's random. (HashSet order is based on hashCode() and capacity, but the exact algorithm is not specified, so it's best to make no assumptions.)
|
 |
 |
|
|
subject: turn a Set into a indexed List?
|
|
|