java之入门语法(Arrays类)

一、Arrays类概述

  • 此类包含用来操作数组(比如排序和搜索)的各种方法,是一个与数组相关的工具类,提供了大量的静态方法,用来实现数组常见的操作。此类还包含一个允许将数组作为列表来查看的静态工厂。
  • 除非特别注明,否则如果指定数组引用为 null,则此类中的方法都会抛出 NullPointerException。
  • 此类中所含方法的文档都包括对实现 的简短描述。应该将这些描述视为实现注意事项,而不应将它们视为规范 的一部分。实现者应该可以随意替代其他算法,只要遵循规范本身即可。(例如,sort(Object[]) 使用的算法不必是一个合并排序算法,但它必须是稳定的。)
  • 此类是 Java Collections Framework 的成员。
  • public static String toString(数组),将参数数组编程字符串(按照默认格式:[元素1,元素2,元素3 ... ...])
  • public static void sort(数组):按照默认升序(从小到大)对数组的元素进行排序。字符串数组也可以进行排序,默认按照字母升序。如果是自定义类型的数组,那么若要使用sort方法,这个自定义的类需要有Comparable或者Comparator接口的支持。

二、方法摘要

static
<T> List<T>
asList(T... a) 
          返回一个受指定数组支持的固定大小的列表。
static intbinarySearch(byte[] a, byte key) 
          使用二分搜索法来搜索指定的 byte 型数组,以获得指定的值。
static intbinarySearch(byte[] a, int fromIndex, int toIndex, byte key) 
          使用二分搜索法来搜索指定的 byte 型数组的范围,以获得指定的值。
static intbinarySearch(char[] a, char key) 
          使用二分搜索法来搜索指定的 char 型数组,以获得指定的值。
static intbinarySearch(char[] a, int fromIndex, int toIndex, char key) 
          使用二分搜索法来搜索指定的 char 型数组的范围,以获得指定的值。
static intbinarySearch(double[] a, double key) 
          使用二分搜索法来搜索指定的 double 型数组,以获得指定的值。
static intbinarySearch(double[] a, int fromIndex, int toIndex, double key) 
          使用二分搜索法来搜索指定的 double 型数组的范围,以获得指定的值。
static intbinarySearch(float[] a, float key) 
          使用二分搜索法来搜索指定的 float 型数组,以获得指定的值。
static intbinarySearch(float[] a, int fromIndex, int toIndex, float key) 
          使用二分搜索法来搜索指定的 float 型数组的范围,以获得指定的值。
static intbinarySearch(int[] a, int key) 
          使用二分搜索法来搜索指定的 int 型数组,以获得指定的值。
static intbinarySearch(int[] a, int fromIndex, int toIndex, int key) 
          使用二分搜索法来搜索指定的 int 型数组的范围,以获得指定的值。
static intbinarySearch(long[] a, int fromIndex, int toIndex, long key) 
          使用二分搜索法来搜索指定的 long 型数组的范围,以获得指定的值。
static intbinarySearch(long[] a, long key) 
          使用二分搜索法来搜索指定的 long 型数组,以获得指定的值。
static intbinarySearch(Object[] a, int fromIndex, int toIndex, Object key) 
          使用二分搜索法来搜索指定数组的范围,以获得指定对象。
static intbinarySearch(Object[] a, Object key) 
          使用二分搜索法来搜索指定数组,以获得指定对象。
static intbinarySearch(short[] a, int fromIndex, int toIndex, short key) 
          使用二分搜索法来搜索指定的 short 型数组的范围,以获得指定的值。
static intbinarySearch(short[] a, short key) 
          使用二分搜索法来搜索指定的 short 型数组,以获得指定的值。
static
<T> int
binarySearch(T[] a, int fromIndex, int toIndex, T key, Comparator<? super T> c) 
          使用二分搜索法来搜索指定数组的范围,以获得指定对象。
static
<T> int
binarySearch(T[] a, T key, Comparator<? super T> c) 
          使用二分搜索法来搜索指定数组,以获得指定对象。
static boolean[]copyOf(boolean[] original, int newLength) 
          复制指定的数组,截取或用 false 填充(如有必要),以使副本具有指定的长度。
static byte[]copyOf(byte[] original, int newLength) 
          复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。
static char[]copyOf(char[] original, int newLength) 
          复制指定的数组,截取或用 null 字符填充(如有必要),以使副本具有指定的长度。
static double[]copyOf(double[] original, int newLength) 
          复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。
static float[]copyOf(float[] original, int newLength) 
          复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。
static int[]copyOf(int[] original, int newLength) 
          复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。
static long[]copyOf(long[] original, int newLength) 
          复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。
static short[]copyOf(short[] original, int newLength) 
          复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。
static
<T> T[]
copyOf(T[] original, int newLength) 
          复制指定的数组,截取或用 null 填充(如有必要),以使副本具有指定的长度。
static
<T,U> T[]
copyOf(U[] original, int newLength, Class<? extends T[]> newType) 
          复制指定的数组,截取或用 null 填充(如有必要),以使副本具有指定的长度。
static boolean[]copyOfRange(boolean[] original, int from, int to) 
          将指定数组的指定范围复制到一个新数组。
static byte[]copyOfRange(byte[] original, int from, int to) 
          将指定数组的指定范围复制到一个新数组。
static char[]copyOfRange(char[] original, int from, int to) 
          将指定数组的指定范围复制到一个新数组。
static double[]copyOfRange(double[] original, int from, int to) 
          将指定数组的指定范围复制到一个新数组。
static float[]copyOfRange(float[] original, int from, int to) 
          将指定数组的指定范围复制到一个新数组。
static int[]copyOfRange(int[] original, int from, int to) 
          将指定数组的指定范围复制到一个新数组。
static long[]copyOfRange(long[] original, int from, int to) 
          将指定数组的指定范围复制到一个新数组。
static short[]copyOfRange(short[] original, int from, int to) 
          将指定数组的指定范围复制到一个新数组。
static
<T> T[]
copyOfRange(T[] original, int from, int to) 
          将指定数组的指定范围复制到一个新数组。
static
<T,U> T[]
copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType) 
          将指定数组的指定范围复制到一个新数组。
static booleandeepEquals(Object[] a1, Object[] a2) 
          如果两个指定数组彼此是深层相等 的,则返回 true。
static intdeepHashCode(Object[] a) 
          基于指定数组的“深层内容”返回哈希码。
static StringdeepToString(Object[] a) 
          返回指定数组“深层内容”的字符串表示形式。
static booleanequals(boolean[] a, boolean[] a2) 
          如果两个指定的 boolean 型数组彼此相等,则返回 true。
static booleanequals(byte[] a, byte[] a2) 
          如果两个指定的 byte 型数组彼此相等,则返回 true。
static booleanequals(char[] a, char[] a2) 
          如果两个指定的 char 型数组彼此相等,则返回 true。
static booleanequals(double[] a, double[] a2) 
          如果两个指定的 double 型数组彼此相等,则返回 true。
static booleanequals(float[] a, float[] a2) 
          如果两个指定的 float 型数组彼此相等,则返回 true。
static booleanequals(int[] a, int[] a2) 
          如果两个指定的 int 型数组彼此相等,则返回 true。
static booleanequals(long[] a, long[] a2) 
          如果两个指定的 long 型数组彼此相等,则返回 true。
static booleanequals(Object[] a, Object[] a2) 
          如果两个指定的 Objects 数组彼此相等,则返回 true。
static booleanequals(short[] a, short[] a2) 
          如果两个指定的 short 型数组彼此相等,则返回 true。
static voidfill(boolean[] a, boolean val) 
          将指定的 boolean 值分配给指定 boolean 型数组的每个元素。
static voidfill(boolean[] a, int fromIndex, int toIndex, boolean val) 
          将指定的 boolean 值分配给指定 boolean 型数组指定范围中的每个元素。
static voidfill(byte[] a, byte val) 
          将指定的 byte 值分配给指定 byte 节型数组的每个元素。
static voidfill(byte[] a, int fromIndex, int toIndex, byte val) 
          将指定的 byte 值分配给指定 byte 型数组指定范围中的每个元素。
static voidfill(char[] a, char val) 
          将指定的 char 值分配给指定 char 型数组的每个元素。
static voidfill(char[] a, int fromIndex, int toIndex, char val) 
          将指定的 char 值分配给指定 char 型数组指定范围中的每个元素。
static voidfill(double[] a, double val) 
          将指定的 double 值分配给指定 double 型数组的每个元素。
static voidfill(double[] a, int fromIndex, int toIndex, double val) 
          将指定的 double 值分配给指定 double 型数组指定范围中的每个元素。
static voidfill(float[] a, float val) 
          将指定的 float 值分配给指定 float 型数组的每个元素。
static voidfill(float[] a, int fromIndex, int toIndex, float val) 
          将指定的 float 值分配给指定 float 型数组指定范围中的每个元素。
static voidfill(int[] a, int val) 
          将指定的 int 值分配给指定 int 型数组的每个元素。
static voidfill(int[] a, int fromIndex, int toIndex, int val) 
          将指定的 int 值分配给指定 int 型数组指定范围中的每个元素。
static voidfill(long[] a, int fromIndex, int toIndex, long val) 
          将指定的 long 值分配给指定 long 型数组指定范围中的每个元素。
static voidfill(long[] a, long val) 
          将指定的 long 值分配给指定 long 型数组的每个元素。
static voidfill(Object[] a, int fromIndex, int toIndex, Object val) 
          将指定的 Object 引用分配给指定 Object 数组指定范围中的每个元素。
static voidfill(Object[] a, Object val) 
          将指定的 Object 引用分配给指定 Object 数组的每个元素。
static voidfill(short[] a, int fromIndex, int toIndex, short val) 
          将指定的 short 值分配给指定 short 型数组指定范围中的每个元素。
static voidfill(short[] a, short val) 
          将指定的 short 值分配给指定 short 型数组的每个元素。
static inthashCode(boolean[] a) 
          基于指定数组的内容返回哈希码。
static inthashCode(byte[] a) 
          基于指定数组的内容返回哈希码。
static inthashCode(char[] a) 
          基于指定数组的内容返回哈希码。
static inthashCode(double[] a) 
          基于指定数组的内容返回哈希码。
static inthashCode(float[] a) 
          基于指定数组的内容返回哈希码。
static inthashCode(int[] a) 
          基于指定数组的内容返回哈希码。
static inthashCode(long[] a) 
          基于指定数组的内容返回哈希码。
static inthashCode(Object[] a) 
          基于指定数组的内容返回哈希码。
static inthashCode(short[] a) 
          基于指定数组的内容返回哈希码。
static voidsort(byte[] a) 
          对指定的 byte 型数组按数字升序进行排序。
static voidsort(byte[] a, int fromIndex, int toIndex) 
          对指定 byte 型数组的指定范围按数字升序进行排序。
static voidsort(char[] a) 
          对指定的 char 型数组按数字升序进行排序。
static voidsort(char[] a, int fromIndex, int toIndex) 
          对指定 char 型数组的指定范围按数字升序进行排序。
static voidsort(double[] a) 
          对指定的 double 型数组按数字升序进行排序。
static voidsort(double[] a, int fromIndex, int toIndex) 
          对指定 double 型数组的指定范围按数字升序进行排序。
static voidsort(float[] a) 
          对指定的 float 型数组按数字升序进行排序。
static voidsort(float[] a, int fromIndex, int toIndex) 
          对指定 float 型数组的指定范围按数字升序进行排序。
static voidsort(int[] a) 
          对指定的 int 型数组按数字升序进行排序。
static voidsort(int[] a, int fromIndex, int toIndex) 
          对指定 int 型数组的指定范围按数字升序进行排序。
static voidsort(long[] a) 
          对指定的 long 型数组按数字升序进行排序。
static voidsort(long[] a, int fromIndex, int toIndex) 
          对指定 long 型数组的指定范围按数字升序进行排序。
static voidsort(Object[] a) 
          根据元素的自然顺序对指定对象数组按升序进行排序。
static voidsort(Object[] a, int fromIndex, int toIndex) 
          根据元素的自然顺序对指定对象数组的指定范围按升序进行排序。
static voidsort(short[] a) 
          对指定的 short 型数组按数字升序进行排序。
static voidsort(short[] a, int fromIndex, int toIndex) 
          对指定 short 型数组的指定范围按数字升序进行排序。
static
<T> void
sort(T[] a, Comparator<? super T> c) 
          根据指定比较器产生的顺序对指定对象数组进行排序。
static
<T> void
sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c) 
          根据指定比较器产生的顺序对指定对象数组的指定范围进行排序。
static StringtoString(boolean[] a) 
          返回指定数组内容的字符串表示形式。
static StringtoString(byte[] a) 
          返回指定数组内容的字符串表示形式。
static StringtoString(char[] a) 
          返回指定数组内容的字符串表示形式。
static StringtoString(double[] a) 
          返回指定数组内容的字符串表示形式。
static StringtoString(float[] a) 
          返回指定数组内容的字符串表示形式。
static StringtoString(int[] a) 
          返回指定数组内容的字符串表示形式。
static StringtoString(long[] a) 
          返回指定数组内容的字符串表示形式。
static StringtoString(Object[] a) 
          返回指定数组内容的字符串表示形式。
static StringtoString(short[] a) 
          返回指定数组内容的字符串表示形式。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值