Forums Register Login

Sorting my list

+Pie Number of slices to send: Send
Hi Guys,

I have a list which containers mail orders from the db which are stored in a session. What Ive noticed when I view the orders on the webpage is that it starts from the oldest date to the newest. I want to switch this around. Is there any way I can do this? See basic structure of list below:

+Pie Number of slices to send: Send
use a compareTo method to sort in reverse order i.e. latest first.


implement a compareTo method in your Mail class. Make sure that it implements the Comparable interface. http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Comparable.html




You can then sort it as shown below. Your compareTo method gets called. Fopr more complex sorting, write your own Comparator. Check the Java API.



http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#sort(java.util.List)

http://www.java2s.com/Tutorial/Java/0140__Collections/SortingaList.htm

[ September 25, 2008: Message edited by: arulk pillai ]

[ September 25, 2008: Message edited by: arulk pillai ]
[ September 25, 2008: Message edited by: arulk pillai ]
+Pie Number of slices to send: Send
Why not sorting them when you query from the DB?
+Pie Number of slices to send: Send
This type of sorting is best done via your SQL when you do your select.
Popeye has his spinach. I have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 948 times.
Similar Threads
Hibernate 3 Annotations
xls:sort question
xsl:sort - Help Required
Hibernate: unexpected queries in parent/child relationship
Entity perisistence with triggers on child
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:44:42.