Java Program to Split the array and add the first part to the end | Set 2 Last Updated : 24 Jan, 2022 Comments Improve Suggest changes Like Article Like Report 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. A O(n*k) solution is discussed here. This problem can be solved in O(n) time using the reversal algorithm discussed below, 1. Reverse array from 0 to n - 1 (where n is size of the array). 2. Reverse array from 0 to n - k - 1. 3. Reverse array from n - k to n - 1. Java // Java program to Split the array and // add the first part to the end class Geeks { /* Function to reverse arr[] from index start to end*/ static void rvereseArray(int arr[], int start, int end) { while (start < end) { int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } } // Function to print an array static void printArray(int arr[], int size) { for (int i = 0; i < size; i++) System.out.print(arr[i] +" "); } /* Function to left rotate arr[] of size n by k */ static void splitArr(int arr[], int k, int n) { rvereseArray(arr, 0, n - 1); rvereseArray(arr, 0, n - k - 1); rvereseArray(arr, n - k, n - 1); } /* Driver program to test above functions */ public static void main(String args[]) { int arr[] = { 12, 10, 5, 6, 52, 36 }; int n = arr.length; int k = 2; // Function calling splitArr(arr, k, n); printArray(arr, n); } } // This code is contributed by ankita_saini. Output: 5 6 52 36 12 10 Please refer complete article on Split the array and add the first part to the end | Set 2 for more details! Comment More infoAdvertise with us Next Article Java Program to Split the array and add the first part to the end | Set 2 K kartik Follow Improve Article Tags : Java Java Programs DSA Arrays rotation array-rearrange Reverse +3 More Practice Tags : ArraysJavaReverse Similar Reads Java Program to Split an Array from Specified Position In Java, splitting an array means dividing the array into two parts based on a given position. This operation creates two new arrays that represent the segments before and after the given index.Example:The simplest way to split an array in Java from a specified position is by using the in-built Arra 4 min read Java Program to Move all zeroes to end of array | Set-2 (Using single traversal) Given an array of n numbers. The problem is to move all the 0's to the end of the array while maintaining the order of the other elements. Only single traversal of the array is required.Examples:Â Â Input : arr[] = {1, 2, 0, 0, 0, 3, 6} Output : 1 2 3 6 0 0 0 Input: arr[] = {0, 1, 9, 8, 4, 0, 0, 2, 7 2 min read Program to convert Array to Set in Java Array is a group of like-typed variables that are referred to by a common name. An array can contain primitives data types as well as objects of a class depending on the definition of the array. In the case of primitives data types, the actual values are stored in contiguous memory locations. In cas 7 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 Convert String to Integer Array In Java, we cannot directly perform numeric operations on a String representing numbers. To handle numeric values, we first need to convert the string into an integer array. In this article, we will discuss different methods for converting a numeric string to an integer array in Java.Example:Below i 3 min read Like