aspose file tools*
The moose likes Java in General and the fly likes turn a Set into a indexed List? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "turn a Set into a indexed List?" Watch "turn a Set into a indexed List?" New topic
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: 18671
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.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: turn a Set into a indexed List?