Forums Register Login

Can a Collection be traversed in reverse order?

+Pie Number of slices to send: Send
Hi..

I am using a List of Objects to display..
When I click a Link, it has to be displayed in the reverse order..
Is there any way to do this..

Please help me..

Thanks in advance..
+Pie Number of slices to send: Send
You can reverse a List with Collections.reverse(). However, that really does reverse it permanently.

You can use a "for" loop and get(int) to go backwards through the list. This is efficient if the implementation is something like an ArrayList, but inefficient if it's something like a LinkedList.
+Pie Number of slices to send: Send
There is also a way to do this more efficiently using a ListIterator, without reversing the original list.
+Pie Number of slices to send: Send
Cool. Never had to do that, but shall now endeavour to remember it, in case it comes up.
Their achilles heel is the noogie! Give them noogies tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1263 times.
Similar Threads
listener register order?
singly inked list traversing in the reverse direction
what is that you most love?
DTO pattern name changed to ValueObject
Order of Listener Notification
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:05:20.