Java Program for Program to cyclically rotate an array by one Last Updated : 05 Sep, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an array, cyclically rotate the array clockwise by one. Examples: Input: arr[] = {1, 2, 3, 4, 5} Output: arr[] = {5, 1, 2, 3, 4}Recommended: Please solve it on "PRACTICE" first, before moving on to the solution. Java import java.util.Arrays; public class Test { static int arr[] = new int[]{1, 2, 3, 4, 5}; // Method for rotation static void rotate() { int x = arr[arr.length-1], i; for (i = arr.length-1; i > 0; i--) arr[i] = arr[i-1]; arr[0] = x; } /* Driver program */ public static void main(String[] args) { System.out.println("Given Array is"); System.out.println(Arrays.toString(arr)); rotate(); System.out.println("Rotated Array is"); System.out.println(Arrays.toString(arr)); } } Time complexity: O(n) as using a for loop Please refer complete article on Program to cyclically rotate an array by one for more details! Comment More infoAdvertise with us Next Article Java.util.Collections.rotate() Method in Java with Examples K kartik Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Java Program to Split the array and add the first part to the end There is a given an array and split it from a specified position, and move the first part of array add to the end. Examples: Input : arr[] = {12, 10, 5, 6, 52, 36} k = 2 Output : arr[] = {5, 6, 52, 36, 12, 10} Explanation : Split from index 2 and first part {12, 10} add to the end . Input : arr[] = 2 min read Reverse an ArrayList in Java using ListIterator Assuming you have gone through arraylist in java and know about arraylist. This post contains different examples for reversing an arraylist which are given below:1. By writing our own function(Using additional space): reverseArrayList() method in RevArrayList class contains logic for reversing an ar 6 min read Reverse an ArrayList in Java using ListIterator Assuming you have gone through arraylist in java and know about arraylist. This post contains different examples for reversing an arraylist which are given below:1. By writing our own function(Using additional space): reverseArrayList() method in RevArrayList class contains logic for reversing an ar 6 min read Java.util.Collections.rotate() Method in Java with Examples java.util.Collections.rotate() method is present in java.util.Collections class. It is used to rotate the elements present in the specified list of Collection by a given distance. Syntax: public static void rotate(List< type > list, int distance) Parameters : list - the list to be rotated. dis 2 min read Array after K Rotations Given an array arr[] and an integer k, rotate the array in place k times to the right (clockwise). In each rotation, the last element moves to the front, and all other elements shift one position to the right. Modify the array in place, do not return anything.Examples : Input: arr[] = [1, 2, 3, 4, 5 12 min read Array after K Rotations Given an array arr[] and an integer k, rotate the array in place k times to the right (clockwise). In each rotation, the last element moves to the front, and all other elements shift one position to the right. Modify the array in place, do not return anything.Examples : Input: arr[] = [1, 2, 3, 4, 5 12 min read Like