java中的常用类 Arrays

java中如果是基本类型 虚拟机 自动赋值 为0 而如果是引用类型则自动赋值为null

  to string 的作用是将对象转换成字符串

         


  然后是基本方法    比较两个数组是否相等.要求是同一类型 

        格式Arrays.equal(a,b )  相同为true  不同为false.


  自己写方法


        填充数组 

      Arrays.fill(type[] a,tape val)   作用于数组的所有元素

        int [] arr3={1,3,2,3};

      eg:Arrays.fill(a,3)

        [3,3,3,3]

    public static void fill(type[] a, int fromIndex, int toIndex, type val)  作用于数组指定范围内的元素

        eg:Arrays.fill(arr3, 2,3,3);  最后一个数不包括

[1, 3, 3, 3]


      排序

     public static void sort(type[] a)  作用于数组的所有元素

    eg: Arrays.sort(arr3);

         [1, 2, 3, 3]

    public static void sort(type[] a, int fromIndex, int toIndex)  作用于数组指定范围内的元素

      eg:    int [] arr3={1,3,2,3,1};
                             //   0 1 2 3 4     java中的读数顺序 

              Arrays.sort(arr3,1,4);

               [ 1, 1, 2, 3, 3]


    数组 搜索 

    Arrays.b    inarySearch   使用搜索方法的前提 : 先要对数组排序

       eg: System.out.println(Arrays.binarySearch(arr3,5));

                 -6    //没有找到


猜你喜欢

转载自blog.csdn.net/qq_41390329/article/details/80726186