File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Reverse the order of elements in a ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reverse the order of elements in a ArrayList" Watch "Reverse the order of elements in a ArrayList" New topic
Author

Reverse the order of elements in a ArrayList

Ramna Reddy
Ranch Hand

Joined: Aug 06, 2006
Posts: 96
Hi Ranchers,
Please give some suggestion for the following problem..
Iam working on web project,
....there is an arraylist which is filled with some data from DB...and displayed in a jsp...
My requirement is to reverse the order of elements....

Collections.reverse(List list) method is not working..

Thank you in advance...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
Collections.reverse(List list) method is not working..


What does this mean? Can you give us a small example of what it does or doesn't do?


Ping & DNS - my free Android networking tools app
Anup Kumar
Greenhorn

Joined: Apr 04, 2007
Posts: 4


Collections.reverse(List list) method is not working..



You can also traverse through the arraylist in reverese order using hasPrevious() method of ListIterator.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"Noble Coder",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names get deleted, often without warning

thanks,
Dave
Ramna Reddy
Ranch Hand

Joined: Aug 06, 2006
Posts: 96
What does this mean? Can you give us a small example of what it does or doesn't do?


Hi Ulf,
When Iam applying.... Collections.reverse(myList);
The list hasn't being reversed.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

What Ulf is saying is that it works for everyone else, why doesn't is work for you?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
Thanks David, that's what I was getting at.

So are you saying that this:


does not print



?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

My apologies, my previous post came out shorter than I wanted.

What I was trying to say is that since reverse() should work but is not, this may be indicating a further problem. Find an alternate solution rather than using reverse() is, in my opinion, working on the wrong problem and may leave you open to errors elsewhere.

Are you able to share any of the code?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reverse the order of elements in a ArrayList