Moves each element in the specified list by the specified distance, the elements whose index becomes more than the list length are moved to the start of the list.
package com.logicbig.example.collections;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class RotateExample {
public static void main(String... args) {
List<String> list = Arrays.asList("one", "two", "three", "four");
System.out.println(list);
Collections.rotate(list, 2);
System.out.println(list);
}
}
Output
[one, two, three, four]
[three, four, one, two]