主要API

  • boolean equals(type[] a, type[] a2); 只有两个数组长度相等,并且每个元素也对应相等时才会返回true
  • type[] copyOf(type[] original, int length); 赋值original数组的前length个元素形成一个新数组返回,如果length大于original的长度,那么多出来的部分系统自动赋予默认值(0/null)
  • void fill(type[] a, type val); // 整个数组填充val
  • void fill(type[] a, int fromIndex, int toIndex, type val); // 区间填充
  • String toString(type[] a); // 分别调用各个元素的toString,将各个结果连缀成一个完整的String返回,中间用", "(逗号+空格分隔);
  • sort(int[] a) // 排序(内部使用优化的快速排序算法)
  • parallelSort(nums); //并行排序
  • binarySearch(int[] a, int key)使用二分法查找元素(注意使用前必须先排序)
  • deepToString(Object[] a)将二维数组转换为String
  • Arrays.hashCode方法计算一个散列码,这个散列码由数组元素的散列码组成

Arrays.copyOf()

  • original - 要复制的数组
  • newLength - 要返回的副本的长度
  • newType - 要返回的副本的类型
public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {
    @SuppressWarnings("unchecked")
    T[] copy = ((Object)newType == (Object)Object[].class)
        ? (T[]) new Object[newLength]
        : (T[]) Array.newInstance(newType.getComponentType(), newLength);
    System.arraycopy(original, 0, copy, 0,
                     Math.min(original.length, newLength));
    return copy;
}

results matching ""

    No results matching ""