Java Array Sub Array subarray(byte[] in, int a, int b)

Here you can find the source of subarray(byte[] in, int a, int b)

Description

Creates and returns a new array with the values of the original from index a to index b and of size (b-a).

License

Open Source License

Parameter

Parameter Description
in input array
a first index
b last index

Return

a new array based on the desired range of the input

Declaration

public static byte[] subarray(byte[] in, int a, int b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from w  ww  .java 2s  .  c  o  m*/
     * Creates and returns a new array with the values of the original from index <code>a</code> to index <code>b</code>
     * and of size <code>(b-a)</code>.
     * @param in input array
     * @param a first index
     * @param b last index
     * @return a new array based on the desired range of the input
     */
    public static byte[] subarray(byte[] in, int a, int b) {
        if (b - a > in.length)
            return in;

        byte[] out = new byte[(b - a) + 1];

        for (int i = a; i <= b; i++) {
            out[i - a] = in[i];
        }
        return out;
    }
}

Related

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