• Post Reply Bookmark Topic Watch Topic
  • New Topic

Records In Collection Object  RSS feed

 
Raj chiru
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Moojid Hamid
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!