Java Collection Tutorial - Java Collections.reverse(List <?> list)








Syntax

Collections.reverse(List <?> list) has the following syntax.

public static void reverse(List <?> list)

Example

In the following code shows how to use Collections.reverse(List <?> list) method.

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
//ww  w.  j a  v a 2s .c o m
public class Main {
   public static void main(String[] args) {
      // create array list object
      List<String>  arrlst = new ArrayList<String>();
      
      // populate the list
      arrlst.add("A");
      arrlst.add("B");
      arrlst.add("C");
      arrlst.add("D");
      arrlst.add("from java2s.com");

      System.out.println("The initial list is :"+arrlst);
      
      // reverse the list
      Collections.reverse(arrlst);
      
      System.out.println("The Reverse List is :"+arrlst);
   }
}

The code above generates the following result.