Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsRotateExample2 { public static void main(String[] args) { //Create array list object List
num = new ArrayList<>(); //Add values in the list for (int i = 1; i <= 10; i++) { num.add(i); } System.out.println("Value Before Rotation: "+Arrays.toString(num.toArray())); //Rotate the list at distance 5 Collections.rotate(num, 5); System.out.println("Value After Rotation: "+Arrays.toString(num.toArray())); } }
Output