java进阶 arrays类44

 

 

 

 

package com.cyjt97.arr;

import java.lang.reflect.Array;
import java.util.Arrays;

public class arr {
    public static void main(String[] args) {
        int arr[] = {11,22,33,44,55,66};
        int arr2[] = {11,22,33,44,55,66};
//        将数组拼成这种格式的字符串返回[11, 22, 33, 44, 55, 66]
        System.out.println(Arrays.toString(arr));
//        Arrays.equals()比较数组内的内容是否相同
        System.out.println(Arrays.equals(arr,arr2));
//        Arrays.binarySearch()根据内容查找数组索引(数组里面的数组必须是排好序的),不存在则根据(-(现有的索引)-1)
        System.out.println(Arrays.binarySearch(arr,33));
        System.out.println(Arrays.binarySearch(arr,363));
//        对数组进行升序排列
        int arr3[] = {46,66,11,33,11,22,33,66};
        Arrays.sort(arr3);
        System.out.println(Arrays.toString(arr3));
    }
}

  

posted @ 2023-03-17 17:36  文采呱呱  阅读(11)  评论(0编辑  收藏  举报