Forums Register Login

sorting VO object sorting based on the attribute

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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

 
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 )

+Pie Number of slices to send: Send
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.
I will suppress my every urge. But not this shameless plug:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3129 times.
Similar Threads
Sorting ArrayList Values inside a TreeMap
how to select a static row at runtime in jsp?
Sorting a List of Value Objects
CachedRowSet
vector sorting
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 23:58:53.