• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sorting Arraylist of ArrayList

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have a arraylist of arraylist which will fetch the value from the database and list the values in jsp page. The arraylist may contain various type of object and the size of the araylist of arraylist will be dynamic i.e will vary. Fro eg the arraylist may look like
[ [Suresh,20, 12/2/02, The test value],
[Xavier,26, 12/1/02, The test value with some other value],
[Varun,2, 1/2/02, The test value],
[Suba,24, 28/2/02, The test value],
]
The constraint is that that arraylist of arraylist must be sorted dynamically based on the datatypes ans well as the particular column.
for eg/ if i want to sort the given arraylist with respect to date value, The result of the sorted arraylist must contain the value based on the date and the order of the inner arraylist i.e the row value must not be changed.
Pls help me in solving the pbm.
thanx
Suba
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
subasuropa -- please review JavaRanch's naming policy, and change your registered name accordingly.
Thanks,
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find a discussion of a very similar problem here.
Chances are, you'll be better off replacing your ArrayList of ArrayLists with an ArrayList of CustomClass objects, where CustomClass is a class you have created to represent the data you're dealing with. In particular, to sort by the third column, date, it will be useful to have a data structure which understands that it is in fact a date, not some random String. Otherwise you will probably get an alphabetic sort, which would lead to problems like 1/1/02 coming before 2/1/01. If you parse these strings as Dates instead, you will be able to make meaningful comparisons.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic