• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

turn a Set into a indexed List?

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)
 
Holmes Wong
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 need a new interior decorator. This tiny ad just painted every room in my house purple.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic