How to print the contents of an array

Code Share:

com.ethjava Package; 

Import java.util.Arrays; 
// how to print the contents of the array 
public class charlianxi { 
    public static void main (String [] args) { 
        // initialize an array of three ways 
        int [] a = {1,2 , 3,4,49}; 
        int [] B = new new int [. 3]; 
        B [0] =. 9; 
        B [. 1] =. 9; 
        B [2] =. 9; 
        String [] = {str1 "AAA", "BBB", "VVV"}; 
        String [] = str2 new new String [] { "FFF", "FFF", "FFF"}; 
        // two-dimensional array 
        String [] [] str = new String [] [] str1 {,} str2; 

        char [] = {CH 'A', 'B', 'C'}; 

        System.out.println (a.toString ()); // [@ 28a418fc the I  
        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)); // [[28a418fc the I @] 
        System.out.println (Arrays.asList (B)); // [[the I @ 5305068a] 
        // array of type int can not Arrays.asList (array) 
        // String type of array can be 
        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] 




    } 
}

 

reference:

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

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

Published 45 original articles · won praise 8 · views 5861

Guess you like

Origin blog.csdn.net/wenyunick/article/details/103497567