Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reverse the order of elements in a ArrayList

 
Ramna Reddy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Anup Kumar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Ulf is saying is that it works for everyone else, why doesn't is work for you?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David, that's what I was getting at.

So are you saying that this:


does not print



?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic