package arrays; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class RotateArray { public static List rotateArray(List arr, int rotations) { int length = arr.size(); rotations = rotations % length; if(rotations < 0) { rotations = rotations+length; } /* * Step 1: copy all the values included in the rotation. * For eg: if rotation = 2, the copy last 2 values into temp array * */ List tempList = new ArrayList<>(); for(int i=(length-rotations); i= rotations; i--) { arr.set(i, arr.get(i-rotations)); } for(int i=0; i