Java Array Sub Array subArray(byte[] in, int start, int end)

Here you can find the source of subArray(byte[] in, int start, int end)

Description

Returns a sub-array of the input array with range specified by the starting (inclusive) and ending (exclusive) indices.

License

Apache License

Parameter

Parameter Description
in a parameter
start a parameter
end a parameter

Declaration

public static final byte[] subArray(byte[] in, int start, int end) 

Method Source Code

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

public class Main {
    /**//from   www .j  av  a 2  s .  co m
     * Returns a sub-array of the input array with range
     * specified by the starting (inclusive) and ending (exclusive) 
     * indices.
     * @param in
     * @param start
     * @param end
     * @return
     */
    public static final byte[] subArray(byte[] in, int start, int end) {
        int N = end - start;
        byte[] out = new byte[N];
        for (int i = 0; i < N; i++) {
            out[i] = in[i + start];
        }
        return out;
    }

    /**
     * Returns a sub-array of the input array with range
     *specified by the starting (inclusive) and ending (exclusive) 
     * indices.
     * @param in
     * @param start
     * @param end
     * @return
     */
    public static final int[] subArray(int[] in, int start, int end) {
        int N = end - start;
        int[] out = new int[N];
        for (int i = 0; i < N; i++) {
            out[i] = in[i + start];
        }
        return out;
    }

    /**
     * Returns a sub-array of the input array with range
     * specified by the starting (inclusive) and ending (exclusive) 
     * indices.
     * @param in
     * @param start
     * @param end
     * @return
     */
    public static final long[] subArray(long[] in, int start, int end) {
        int N = end - start;
        long[] out = new long[N];
        for (int i = 0; i < N; i++) {
            out[i] = in[i + start];
        }
        return out;
    }

    /**
     * Returns a sub-array of the input array with range
     * specified by the starting (inclusive) and ending (exclusive) 
     * indices.
     * @param in
     * @param start
     * @param end
     * @return
     */
    public static final float[] subArray(float[] in, int start, int end) {
        int N = end - start;
        float[] out = new float[N];
        for (int i = 0; i < N; i++) {
            out[i] = in[i + start];
        }
        return out;
    }

    /**
     * Returns a sub-array of the input array with range
     * specified by the starting (inclusive) and ending (exclusive) 
     * indices.
     * @param in
     * @param start
     * @param end
     * @return
     */
    public static final double[] subArray(double[] in, int start, int end) {
        int N = end - start;
        double[] out = new double[N];
        for (int i = 0; i < N; i++) {
            out[i] = in[i + start];
        }
        return out;
    }
}

Related

  1. subArray(byte[] byteArray, int beginIndex, int length)
  2. subArray(byte[] data, int offset, int length)
  3. subArray(byte[] data, int offset, int length)
  4. subarray(byte[] in, int a, int b)
  5. subarray(byte[] in, int arg1, int arg2)
  6. subArray(byte[] input, int start)
  7. subArray(byte[] source, int start, int len)
  8. subarray(byte[] src, int beginIndex)
  9. subArray(byte[] src, int offset, int len)