Prev Next

Java / List and its implementations

How do I reverse an ArrayList in Java?

Using Collections.reverse (list) an ArrayList elements can be reversed. The method does not return a reversed list instead it reverses the same list.

ArrayList aList = new ArrayList();
//Add elements to ArrayList object
aList.add("1");
aList.add("2");
aList.add("3");
aList.add("4");
aList.add("5");
Collections.reverse(aList);
System.out.println("After Reversing the ArrayList Elements are: " + aList);

More Related questions...

Show more question and Answers...


Comments & Discussions