Java中与数组相关的工具类

public static String toString(数组):将参数数组变成字符串(按照默认格式:[元素1,元素2,元素3....])

示例:

    public static void main(String[] args) {

        int [] arrays={10,20,30,40,50,60};
        String str = Arrays.toString(arrays);
        System.out.println(str);
    }

public static void sort(数组):按照默认升序(从小到大)对数组的元素进行排序。(若是数值,默认按照升序从小到大;如果是字符串,sort默认按照字母升序;如果是自定义类型需要有comparable或者comparator接口的支持。)

示例:

    public static void main(String[] args) {

        int [] arrays1={110,240,130,40,530,60};
        Arrays.sort(arrays1);
        System.out.println(Arrays.toString(arrays1));   
    }
# java  

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×