• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sorting arraylist of objects  RSS feed

 
Arulanand Dayalan
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to sort an arraylist of VO as per the following requirement.My VO looks like this.

public class listBaseVO extends BaseVO implements java.io.Serializable {

String bus_unit_cd;
String strName;
String role_cd;
String rcv_stts_cd;

//Get Set Methods

}

I want to sort the arraylist first with bus_unit_cd (By alphabetical order) and then by role code for each of this bus_unit_cd. This is not by alphabetical order. I have three roles EC,MGR,REP. First MGR should be dsipalyed, then EC and the last as REP. Then we should sort rcv_stts_Cd for each of these roles.(Two rcv_Stts_Cd - 01,02). Then for each role code we need sort by name this is in alphabetical order.

Can anyone suggest a way to implement this. Can any one give the sample code to implement the same. This would be of great help to me.

Thanks in advance.

Regards,
Arul.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Implement a java.util.Comparator, or make the VO implement java.util.Comparable; then use one of the static Collections.sort() methods.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!