- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to shift array elements to the right
Let us first create an int array −
int[] arr = { 10, 20, 30, 40, 50, 60, 70, 80, 90 };
Now, shift array elements to the right with arraycopy() and placing the elements correctly so that it gets shifted to the right −
System.arraycopy(arr, 0, arr, 1, arr.length - 1);
Example
import java.util.Arrays; public class Demo { public static void main(String[] argv) throws Exception { int[] arr = { 10, 20, 30, 40, 50, 60, 70, 80, 90 }; System.out.println("Initial array...
"+Arrays.toString(arr)); System.arraycopy(arr, 0, arr, 1, arr.length - 1); System.out.println("Array after shifting to the right..."); System.out.println(Arrays.toString(arr)); } }
Output
Initial array... [10, 20, 30, 40, 50, 60, 70, 80, 90] Array after shifting to the right... [10, 10, 20, 30, 40, 50, 60, 70, 80]
- Related Articles
- Java Program to shift array elements to the left
- Shift the bits of integer array elements to the right in Numpy
- Shift the bits of array elements of a Two-Dimensional array to the right in Numpy
- Shift certain array elements to front of array - JavaScript
- Python program to right rotate the elements of an array
- Shift the bits of integer array elements to the left in Numpy
- Java Program to Print the Elements of an Array
- Shift right in a BigInteger in Java
- Bitwise right shift operator in Java\n
- Shift last given number of elements to front of array JavaScript
- Shift the bits of array elements of a Two-Dimensional array to the left in Numpy
- Java Program to shift bits in a BigInteger
- How to shift the colorbar position to right in matplotlib?
- Java Program to fill elements in a float array
- Java Program to fill elements in a short array

Advertisements