Arrays工具类的使用

java.util.Arrays

  1. boolean equals (int[] a,int[] b) 判断两个数组是否相等

  2. String toString(int[] a) 输出数组信息

  3. void fill(int[] a,int val) 将指定值填充到数组中(全部替换)

  4. void sort(int[] a) 排序(从小到大)底层为快排

  5. int binarySearch (int[] a,int key) 二分查找,返回负数表示没找到

数组中常见的异常

  1. 数组角标越界 ArrayIndexOutOfBoundsException

  2. 空指针异常 NullPointerException

(1)int[] a = new int[3]; a = null;

(2)int arr = new int [4] []; arr[0] [0]

(3)String str[] = new String []{null,"BB",CC};str[0].toString();

posted @ 2021-12-23 16:34  清水煮岁月  阅读(27)  评论(0编辑  收藏  举报