Java Program to Split the array and add the first part to the end Last Updated : 05 Dec, 2018 Comments Improve Suggest changes Like Article Like Report 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[] = {3, 1, 2} k = 1 Output : arr[] = {1, 2, 3} Explanation : Split from index 1 and first part add to the end. Java // Java program to split array and move first // part to end. import java.util.*; import java.lang.*; class GFG { public static void splitArr(int arr[], int n, int k) { for (int i = 0; i < k; i++) { // Rotate array by 1. int x = arr[0]; for (int j = 0; j < n - 1; ++j) arr[j] = arr[j + 1]; arr[n - 1] = x; } } // Driver code public static void main(String[] args) { int arr[] = { 12, 10, 5, 6, 52, 36 }; int n = arr.length; int position = 2; splitArr(arr, 6, position); for (int i = 0; i < n; ++i) System.out.print(arr[i] + " "); } } // Code Contributed by Mohit Gupta_OMG <(0_o)> Output: 5 6 52 36 12 10 Please refer complete article on Split the array and add the first part to the end for more details! Comment More infoAdvertise with us Next Article Java program to expand a String if range is given? K kartik Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Java Program to Convert an Array into a List In Java, arrays and lists are two commonly used data structures. While arrays have a fixed size and are simple to use, lists are dynamic and provide more flexibility. There are times when you may need to convert an array into a list, for instance, when you want to perform operations like adding or r 4 min read Java Program to Convert an Array into a List In Java, arrays and lists are two commonly used data structures. While arrays have a fixed size and are simple to use, lists are dynamic and provide more flexibility. There are times when you may need to convert an array into a list, for instance, when you want to perform operations like adding or r 4 min read Java program to expand a String if range is given? Suppose we have given a string in which some ranges as specified and we have to place the numbers which is between the given range in the specified place as provided and depicted in the illustration below as follows for a better understanding. Illustration: Input : string x = "1-5, 8, 11-14, 18, 20, 6 min read How to get slice of a Primitive Array in Java Given a Primitive Array, the task is to get a Slice of this array in Java, using start and ending index. Examples: Input: arr[] = {1, 2, 3, 4, 5}, startIndex = 2, endIndex = 4 Output: {3, 4, 5} Input: arr[] = {1, 2, 3, 4, 5}, startIndex = 0, endIndex = 1 Output: {1, 2}Method 1: Naive Method.Get the 8 min read How to get slice of a Primitive Array in Java Given a Primitive Array, the task is to get a Slice of this array in Java, using start and ending index. Examples: Input: arr[] = {1, 2, 3, 4, 5}, startIndex = 2, endIndex = 4 Output: {3, 4, 5} Input: arr[] = {1, 2, 3, 4, 5}, startIndex = 0, endIndex = 1 Output: {1, 2}Method 1: Naive Method.Get the 8 min read Find first and last element of ArrayList in java Prerequisite: ArrayList in Java Given an ArrayList, the task is to get the first and last element of the ArrayList in Java, Examples: Input: ArrayList = [1, 2, 3, 4] Output: First = 1, Last = 4 Input: ArrayList = [12, 23, 34, 45, 57, 67, 89] Output: First = 12, Last = 89 Approach: Get the ArrayList 2 min read Like