Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Java program to reverse ArrayList elements

  • How to reverse an ArrayList in java.
  • By using Collections.reverse() method we can reverse ArrayList in java.



#1: Java Example program to reverse ArrayList 

  1. package com.instanceofjava;

  2. import java.util.ArrayList;
  3. import java.util.Collections;

  4. public class ReverseArrayList {
  5. /**
  6. * @author www.Instanceofjava.com
  7. * @category interview questions
  8. * Description: Java Example program to reverse an ArrayList
  9. *
  10. */
  11. public static void main(String[] args) {
  12. ArrayList arrayList= new ArrayList();
  13. arrayList.add("Apple");
  14. arrayList.add("Banana");
  15. arrayList.add("Orange");
  16. Collections.reverse(arrayList);
  17. System.out.println(arrayList);
  18. }

  19. }


Output:

  1. [Orange, Banana, Apple]


#2: Java Example program to print arraylist in reverse order 





This post first appeared on Java Tutorial - InstanceOfJava, please read the originial post: here

Share the post

Java program to reverse ArrayList elements

×

Subscribe to Java Tutorial - Instanceofjava

Get updates delivered right to your inbox!

Thank you for your subscription

×