首页javaarrayJava Collection - 如何从偏移处开始的数组获取子数组

Java Collection - 如何从偏移处开始的数组获取子数组

我们想知道如何从偏移处开始的数组获取子数组。
  
/*
 * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
 *
 * Licensed under the Aduna BSD-style license.
 */

public class Utils {
  /**
   * Gets the subarray from <tt>array</tt> that starts at <tt>offset</tt>.
   */
  public static byte[] get(byte[] array, int offset) {
    return get(array, offset, array.length - offset);
  }

  /**
   * Gets the subarray of length <tt>length</tt> from <tt>array</tt>
   * that starts at <tt>offset</tt>.
   */
  public static byte[] get(byte[] array, int offset, int length) {
    byte[] result = new byte[length];
    System.arraycopy(array, offset, result, 0, length);
    return result;
  }
}