Easy Tutorial
❮ Data Replace Number Todegrees ❯

Java Example - List Element Rotation

Java Examples

The following example demonstrates how to use the rotate() method of the Collections class to rotate elements in a list, with the second parameter specifying the starting position for the rotation:

Main.java File

import java.util.*;

public class Main {
   public static void main(String[] args) {
      List list = Arrays.asList("one Two three Four five six".split(" "));
      System.out.println("List :" + list);
      Collections.rotate(list, 3);
      System.out.println("rotate: " + list);
   }
}

The output of the above code is:

List :[one, Two, three, Four, five, six]
rotate: [Four, five, six, one, Two, three]

Java Examples

❮ Data Replace Number Todegrees ❯