Reverse order of all elements of ArrayList - Java Collection Framework

Java examples for Collection Framework:ArrayList

Description

Reverse order of all elements of ArrayList

Demo Code

 
import java.util.ArrayList;
import java.util.Collections;
 
public class Main {
 
  public static void main(String[] args) {
 
    ArrayList arrayList = new ArrayList();
   /*from   w w  w .  j  a va2s  .c  om*/
    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("C");
    arrayList.add("D");
    arrayList.add("E");
   
    System.out.println("Before Reverse Order, ArrayList Contains : " + arrayList);
   
    Collections.reverse(arrayList);
   
    System.out.println("After Reverse Order, ArrayList Contains : " + arrayList);
   
  }
}

Result


Related Tutorials