Logically it does not work and you should reverse your loop:
for (int i = position-1; i >= 0; i--) {
array[i+1] = array[i];
}
Alternatively you can use
System.arraycopy(array, 0, array, 1, position);
More Related Contents:
- How to remove repetition in output results in this code
- Write a program that takes an array/arraylist of integer and finds longest sub array/arraylist whose entries are equal [closed]
- Finding the max/min value in an array of primitives using Java
- Connect 4 check for a win algorithm
- Quickest way to find missing number in an array of numbers
- Finding the second highest number in array
- Java, find intersection of two arrays
- Find duplicate element in array in time O(n)
- All possible combinations of an array
- Flatten nested arrays in java
- How to find the only number in an array that doesn’t occur twice [duplicate]
- Generate Random Numbers in Array [duplicate]
- find an element in a sorted matrix [duplicate]
- Interview question – Search in sorted array X for index i such that X[i] = i
- In selection sort, if we have two duplicate elements, what is the behavior of the algorithm?
- Java while loop query [closed]
- How do I declare and initialize an array in Java?
- Are arrays passed by value or passed by reference in Java? [duplicate]
- Where is array’s length property defined?
- Java: Reading a file into an array
- Why does my sorting loop seem to append an element where it shouldn’t?
- Can an array be used as a HashMap key?
- varargs and the ‘…’ argument
- How to find the index of an element in an int array?
- Splitting String and put it on int array
- How to get unique items from an array?
- Why does printing a Java array show a memory location [duplicate]
- Printing out a 2D array in matrix format
- How to convert a Java String to an ASCII byte array?
- Converting an int array to a String array