In Java 5 ,你能夠使用 Arrays.toString(arr)
or Arrays.deepToString(arr)用來打印數組
java
Example:數組
// simple array String[] array = new String[] {"John", "Mary", "Bob"}; System.out.println(Arrays.toString(array)); //output: [John, Mary, Bob] // nested array String[][] deepArray = new String[][] {{"John", "Mary"}, {"Alice", "Bob"}}; System.out.println(Arrays.toString(deepArray)); //output: [[Ljava.lang.String;@106d69c, [Ljava.lang.String;@52e922] System.out.println(Arrays.deepToString(deepArray)); //output: [[John, Mary], [Alice, Bob]] //double Array double[] arrayGiven = { 7.0, 9.0, 5.0, 1.0, 3.0 }; System.out.println(Arrays.toString(arrayGiven)); // Output [7.0, 9.0, 5.0, 1.0, 3.0 ] //int Array int[] arrayInt = { 7, 9, 5, 1, 3 }; System.out.println(Arrays.toString(arrayInt)); // Output [7, 9, 5, 1, 3 ]