Java Arrays 工具类使用

更多 Java 基础知识方面的文章,请参见文集《Java 基础知识》


以 Java 7 API 为参照。

排序

void sort(int[] a)
void sort(int[] a, int fromIndex, int toIndex)
注意:包含 fromIndex,不包含 toIndex

void sort(T[] a, Comparator<? super T> c)

The sorting algorithm is a Dual-Pivot Quicksort 使用快速排序

搜索

int binarySearch(int[] a, int key)
int binarySearch(int[] a, int fromIndex, int toIndex, int key)

判断相等

boolean equals(int[] a, int[] a2)

Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal.

填充

void fill(int[] a, int val)
void fill(int[] a, int fromIndex, int toIndex, int val)

复制

int[] copyOf(int[] original, int newLength)

truncated or padded with zeros to obtain the specified length

int[] copyOfRange(int[] original, int from, int to)

转换为链表

List<T> asList(T... a)

转换为字符串

String toString(int[] a)


引用:
Class Arrays

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容