Java Array Shift shiftArgs(final String[] args)

Here you can find the source of shiftArgs(final String[] args)

Description

Shifts an array of strings by one item to the left.

License

Apache License

Parameter

Parameter Description
args array of strings

Return

the current array shifted by one item or an empty array if there are no items to shift.

Declaration

public static String[] shiftArgs(final String[] args) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;

public class Main {
    /**//from   ww  w . j a v a  2 s  .com
     * Shifts an array of strings by one item to the left.
     * @param args array of strings
     * @return the current array shifted by one item or an empty array
     *         if there are no items to shift.
     */
    public static String[] shiftArgs(final String[] args) {
        return shiftArgs(args, 1);
    }

    /**
     * Shifts an array of strings by the specified number of items to
     * the left.
     * @param args array of strings
     * @return the current array shifted by the specified number of
     *         items or an empty array if there aren't enough items
     *         to shift.
     */
    public static String[] shiftArgs(final String[] args, final int count) {
        if (count > args.length) {
            return new String[] {};
        }
        return Arrays.copyOfRange(args, count, args.length);
    }
}

Related

  1. shift(String[] in)
  2. shift(String[] original, int offset)
  3. shift(String[] src, String word)
  4. shift(String[] tokens)
  5. shift(T[] array, int count)
  6. shiftArgs(String[] args, int offset)
  7. shiftArray(String[] args, int shift)
  8. shiftArray(String[] array, int offset)
  9. ShiftAwayTrailingZerosTwoElements(int[] arr)