Java List rotate element

Description

Java List rotate element


import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class Main {

  public static void main(String args[]) {

    List<Character> ll = new LinkedList<Character>();

    for (char n = 'A'; n <= 'F'; n++)
      ll.add(n);/*from ww  w .j  av  a 2  s. c  om*/

    System.out.println(ll);

    Collections.rotate(ll, 1);

    System.out.println(ll);

    Collections.rotate(ll, 2);

    System.out.println(ll);

  }
}



PreviousNext

Related