0

Hi i am having the data on table in one field "ByYear" it contain the data years like 2005-2006, and the field type is varchar(10), the table data contains the following list... now my requirement was, i have to show the ByYear field data in Combo box in accending order on my Jsp page, here we can take value for accending by first year(2005 among 2005-2009). ru get the point?...... here i am showing the data of my table

ByYear
---------
2009-2010
2010-2011
2006-2009
2007-2009
2009-2010
2010-2011
2011-2012
2010-2011
Naresh
  • 245
  • 1
  • 7
  • 18

2 Answers2

0

Collections.sort(list, implementation of comparator)

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438
  • can u give the discription about that implementation of comparator – Naresh Jan 27 '11 at 09:57
  • Comparator is an interface . . [more](http://download.oracle.com/javase/6/docs/api/java/util/Comparator.html) check the link too from post , – jmj Jan 27 '11 at 10:02
  • can u send me an example code for that which matches for my requirement – Naresh Jan 27 '11 at 10:21
  • I have pointed to example, you can easily construct the code from there. – jmj Jan 27 '11 at 10:22
0

An alternative to writing a custom comparator would be to create your own subclass which implements Comparable and then define a compareTo method as detailed here.

I personally prefer implementing a compareTo, as it allows you to use the various sorts built into other classes, rather than being restricted to only your Comparator class.

Zulaxia
  • 2,702
  • 2
  • 22
  • 23