简体   繁体   中英

how to show the list data in ascending order?

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

Collections.sort(list, implementation of comparator)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM