Java Collections reverse List

Description

Java Collections reverse List

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    // create and display a List<Character>
    Character[] letters = { 'J', 'D', 'K' };
    List<Character> list = Arrays.asList(letters); // get List
    System.out.println("list contains: ");
    System.out.println(list);//from  w  w w  . j a v a  2  s  .  co  m

    // reverse and display the List<Character>
    Collections.reverse(list); // reverse order the elements
    System.out.printf("%nAfter calling reverse, list contains:%n");
    System.out.println(list);

  }
}



PreviousNext

Related