Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reversing an ArrayList

 
K Sujit
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose my arraylist contains objects
ob2, ob3,ob5 and ob1
I want to reverse the order of the objects in the ArrayList.
That is I want it to be
ob1, ob5, ob3 and ob2.

is there any function like(though I didn't find in Javadoc)
arrayListInstance.reverse();
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try Collections.reverse(arrayList);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic