如何打印数组内容

﹥>﹥吖頭↗ 提交于 2019-12-12 00:09:02

代码分享:

package com.ethjava;

import java.util.Arrays;
//如何打印数组内容
public class charlianxi {
    public static void main(String[] args) {
        //数组初始化的三种方式
        int[] a={1,2,3,4,49};
        int[] b=new int[3];
        b[0]=9;
        b[1]=9;
        b[2]=9;
        String[] str1={"aaa","bbb","vvv"};
        String[] str2=new String[]{"fff","fff","fff"};
        //二维数组
        String[][] str=new String[][]{str1,str2};

        char[] ch={'a','b','c'};

        System.out.println(a.toString());//[I@28a418fc
        System.out.println(b.toString());//[I@5305068a
        System.out.println(str1.toString());//[Ljava.lang.String;@1f32e575
        System.out.println(str2.toString());//[Ljava.lang.String;@279f2327
        System.out.println(str.toString());//[[Ljava.lang.String;@2ff4acd0
        System.out.println(ch.toString());//[C@54bedef2


        System.out.println(Arrays.toString(a));//[1, 2, 3, 4, 49]
        System.out.println(Arrays.toString(b));//[9, 9, 9]
        System.out.println(Arrays.toString(str1));//[aaa, bbb, vvv]
        System.out.println(Arrays.toString(str2));//[fff, fff, fff]
        System.out.println(Arrays.deepToString(str));//[[aaa, bbb, vvv], [fff, fff, fff]]
        System.out.println(Arrays.toString(ch));//[a, b, c]


        System.out.println(Arrays.asList(a));//[[I@28a418fc]
        System.out.println(Arrays.asList(b));//[[I@5305068a]
        //int类型的数组不能用Arrays.asList(数组)
        //String类型的数组可以
        System.out.println(Arrays.asList(str1));//[aaa, bbb, vvv]
        System.out.println(Arrays.asList(str2));//[fff, fff, fff]
        System.out.println(Arrays.asList(str));//[[Ljava.lang.String;@5305068a, [Ljava.lang.String;@1f32e575]




    }
}

 

参考:

https://blog.csdn.net/qq_32575047/article/details/78880283?utm_source=app

https://blog.csdn.net/mxd446814583/article/details/79591672?utm_source=app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!