Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsRotateExample3 { public static void main(String[] args) { //Create an array of integers Integer arr[] = {10, 20, 30, 40, 50}; System.out.println("Original Array: "+Arrays.toString(arr)); //Rotating an array by distance -2 Collections.rotate(Arrays.asList(arr), -2); System.out.println("Modified Array: "+Arrays.toString(arr)); } }
Output