Java Array Range Copy copyOf(byte[] bytes, int startIndex, int length)

Here you can find the source of copyOf(byte[] bytes, int startIndex, int length)

Description

Returns a new byte array of 'length' size containing the contents of the provided 'bytes' array beginning at startIndex to (startIndex+length-1)

License

Apache License

Parameter

Parameter Description
bytes a parameter
startIndex a parameter
length a parameter

Declaration

public static byte[] copyOf(byte[] bytes, int startIndex, int length) 

Method Source Code

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

public class Main {
    /**/*from   w w  w  .j a  va2s  .  c  o m*/
     * Returns a new byte array of 'length' size containing the contents of the provided 'bytes' array beginning at startIndex to (startIndex+length-1)
     * 
     * @param bytes
     * @param startIndex
     * @param length
     * @return
     */
    public static byte[] copyOf(byte[] bytes, int startIndex, int length) {
        byte[] newByteArray = new byte[length];
        for (int i = 0; i < length; i++) {
            newByteArray[i] = bytes[i + startIndex];
        }
        return newByteArray;
    }
}

Related

  1. copyOf(byte[] arr, int newLength)
  2. copyOf(byte[] b)
  3. copyOf(byte[] b, int off, int len)
  4. copyOf(byte[] b, int off, int len)
  5. copyOf(byte[] bytes)
  6. copyOf(byte[] original, int newLength)
  7. copyOf(byte[] original, int newLength)
  8. copyOf(byte[] original, int newLength)
  9. copyOf(byte[] original, int newLength)