Java Array Sub Array subArray(String[] data, int index, int length)

Here you can find the source of subArray(String[] data, int index, int length)

Description

Returns a subarray of the given array.

License

Apache License

Parameter

Parameter Description
data The original array.
index The start index.
length The length that should get copied.

Return

The subarray.

Declaration

public static String[] subArray(String[] data, int index, int length) 

Method Source Code

//package com.java2s;
/*/*w ww . j a  v  a  2  s. c  o m*/
 * Copyright 2012 BMW Car IT GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Returns a subarray of the given array.
     * 
     * @param data
     *            The original array.
     * @param index
     *            The start index.
     * @param length
     *            The length that should get copied.
     * @return The subarray.
     */
    public static String[] subArray(String[] data, int index, int length) {
        if (index + length > data.length) {
            throw new IllegalArgumentException("invalid length of input array");
        }
        String[] result = new String[length];
        System.arraycopy(data, index, result, 0, length);
        return result;
    }
}

Related

  1. subArray(Object[] arr, int start, int length)
  2. subArray(Object[] data, int startIndex, int endIndex)
  3. subArray(String a[], int from)
  4. subarray(String[] args, String sep)
  5. subArray(String[] array, int start, int endExclusive)
  6. subarray(String[] master, int index)
  7. subArray(String[] strings, int nStart)
  8. subarray(T[] a, int off, int len)
  9. subArray(T[] array, int start, int end)