• Post Reply Bookmark Topic Watch Topic
  • New Topic

Method to sort by month  RSS feed

 
a gandhi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have records with names JAN03, FEB23, APR05, FEB 03, JAN 15, etc. I need to sort them by month. The o/p should be
JAN 03
JAN 15
FEB 03
FEB 23
APR 05
Can any one suggest me how to go about it??
Thanks..
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Create a java.text.SimpleDateFormat which can parse strings like JAN03, FEB23, ... as Dates.
2. Create a java.util.Comparator with a compareTo() method which can take two records, convert both their names to Dates (using the SimpleDateFormat), and compare the Dates.
3. Use Arrays.sort() or Collections.sort() to sort your array or Collection of records using the Comparator.
Naturally, for each of these steps you can learn more by consulting the API for that class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!