Java Array Shift shiftRight(Object[] array, final int amount)

Here you can find the source of shiftRight(Object[] array, final int amount)

Description

Shift array given number of times

License

Open Source License

Parameter

Parameter Description
array dat array
amount dat number of times

Declaration

public static void shiftRight(Object[] array, final int amount) 

Method Source Code

//package com.java2s;
/*/*  ww w .  j  a v a2  s  .  c  o m*/
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 Andrzej Ressel (jereksel@gmail.com)
 * Copyright (c) 2014 Mateusz Kaleci?ski
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

public class Main {
    /**
     * Shift array given number of times
     *
     * @param array  dat array
     * @param amount dat number of times
     */
    public static void shiftRight(Object[] array, final int amount) {
        for (int j = 0; j < amount; j++) {
            final Object temp = array[array.length - 1];
            int index;
            for (index = array.length - 1; index > 0; index--) {
                array[index] = array[index - 1];
            }
            array[index] = temp;
        }
    }
}

Related

  1. shiftOnRow(double[][] d, int q)
  2. shiftRight(byte[] block)
  3. shiftRight(byte[] x)
  4. shiftRight(int[] result, int[] vec, int shift)
  5. shiftRight(int[] x)
  6. shiftRight(T[] array)
  7. shiftRight2(T[] array, int to)
  8. shiftRightN(int[] block, int n)
  9. shiftRightN(int[] block, int n)