• Post Reply Bookmark Topic Watch Topic
  • New Topic

sorting VO object sorting based on the attribute  RSS feed

 
prakash jaya
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI all,

how can i achieve VO object sorting based on the attribute.

I have an employeeVO which contains like empno, empname, emplocation. how to sort this VO ( it will be an array list) based on the attributes..

Please help me Thanks
 
prakash jaya
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
prakash jaya wrote:HI all,

how can i achieve VO object sorting based on the attribute.

I have an employeeVO which contains like empno, empname, emplocation. how to sort this VO ( it will be an array list) based on the attributes..

Please help me Thanks
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prakash,
Welcome to the Ranch.

Check out Collections#sort(List data,Comparator comparator). Essentially the comparator defines, what criteria should be used for sorting. In your case, it will be based on the VO attributes.
You can find some example code here

I am moving this to a more suitable forum.
 
Shyam Ramath
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your VO bean Class should implement comparator interface . Then you should decide the member variable on which this sorting should happen .
Implement these logic in the compareto() method (Abstract method in comparator interface )

 
DurgaPrasad Chowdhary.
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prakash,

You have two choices to accomplish the task.
1. If you can change the VO class then implement Comparable interface and provide implementation to copare method.
compare method will have one formal argument, which you have to compare with current object on which compare is going to be called.
2. If you cannot change the VO class then write separate class which implements Comparator and provide implementation to compare method.
here method will have two formal arguments, which you need to compare.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!