Java Array Sub Array subarray(byte[] array, int startIndexInclusive, int endIndexExclusive)

Here you can find the source of subarray(byte[] array, int startIndexInclusive, int endIndexExclusive)

Description

subarray

License

Open Source License

Declaration

public static byte[] subarray(byte[] array, int startIndexInclusive, int endIndexExclusive) 

Method Source Code

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

public class Main {
    public static byte[] subarray(byte[] array, int startIndexInclusive, int endIndexExclusive) {
        if (array == null) {
            return null;
        }//from  w w w.j  a v  a 2  s.c  om
        if (startIndexInclusive < 0) {
            startIndexInclusive = 0;
        }
        if (endIndexExclusive > array.length) {
            endIndexExclusive = array.length;
        }
        int newSize = endIndexExclusive - startIndexInclusive;
        if (newSize <= 0) {
            return new byte[0];
        }

        byte[] subarray = new byte[newSize];
        System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
        return subarray;
    }
}

Related

  1. sub(T[] source, int first, int last)
  2. subarray(boolean[] array, int fromIndex, int length)
  3. subArray(byte[] a, int beginIndex, int endIndex)
  4. subArray(byte[] array, int beginIndex, int endIndex)
  5. subarray(byte[] array, int offset, int length)
  6. subarray(byte[] array, int startIndexInclusive, int endIndexExclusive)
  7. subArray(byte[] b, int offset, int length)
  8. subarray(byte[] b, int ofs, int len)
  9. subArray(byte[] byteArray, int beginIndex, int length)