● Arrays类用于操作数组工具类,里面定义了常见操作数组的静态方法。
equals 方法
● 比较两个非同一数组是否相等,而数组本身的equals判断另一个数 组是否它本身。
● 声明:public static boolean equals(type[]a,type[]a2)
● 参数的类型可以是原生数据类型和引用类型的任意一种类型。
● 返回:如果两个相等,则返回true,否则返回false
sort -排序
● 作用于数组的所有元素 public static void sort(type[] a)
● 作用于数组指定范围内的元素 public static void sort(type[] a, int fromIndex(包括), int toIndex(不包括)) 将指定的类型(除boolean以外的任意原生数据类型)数组所有元素(或指定范 围内的元素)按数字升序进行排序。 object型数组,根据元素的自然顺序,对指定对象数组进行升序排序。 (fromIndex==toIndex,则排序范围为空)
● 自定义对象排序 自定义类实现Comparable接口 重写compareTo方法
binarySearch -使用二分搜索算法搜索指定数组
● 声明: public static int binarySearch(type[] a, type key)
public static int binarySearch(long[] a,int fromIndex,int toIndex,long key)
● 描述: 使用二分搜索算法搜索指定的type型数组,以获得指定的值。
● 参数: a - 要搜索的数组。
key - 要搜索的值。
fromIndex - 要排序的第一个元素的索引(包括)。
toIndex - 要排序的最后一个元素的索引(不包括)。
type -byte、double、float、object、long、int、short、char
● 如果key在数组中,则返回搜索值的索引;否则返回-1或者 ”-“ (插入点)
toString() 方法
● 声明:public static String toString(type[] a)
● 描述:返回指定数组内容的字符串表示形式。
● 基本数组,字符串表示形式由数组的元素列表组成,括在[],相邻元素 用“ , ”(逗号加空格)分隔。