• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Records In Collection Object

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.......
if i have ten records in my data base, but i want to get those records from the database and put those records in collection object,
my dout is which collection object is used in this scenario, and i want elements (or records) should be sorting order.
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want sorted, there are two options: SortedSet (implemented by TreeSet) or List (ArrayList, LinkedList) in combination with Arrays.sort.

I'd go with SortedSet unless you have duplicate records; then SortedSet is no longer an option.
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMO List (ArrayList, LinkedList) would be a better option *if* the only source of records is the database. When retrieving the records use the SQL order by clause and there will be no need to sort.

However if more records are added to the collection after filling it with the database records, I would say following Rob's suggestion.
reply
    Bookmark Topic Watch Topic
  • New Topic