• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sorting VO object sorting based on the attribute

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 )

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic