對於一個一維陣列,他在轉換成字串的時候應該呼叫Arrays.toString();
對於一個多維陣列,他在轉換成字串的時候應該呼叫Arrays.deepToString();
例項:
package study; import java.util.Arrays; public class de { public static void main(String[] args) { int[] a={1,2,3,3,3,4,44,4,5,5,4,5,6,7}; System.out.println(Arrays.toString(a)); int[][] a1={{3,3,3,4,44,4},{5,5,4,5,6,7}}; System.out.println(Arrays.deepToString(a1)); } }
結果:
1 [1, 2, 3, 3, 3, 4, 44, 4, 5, 5, 4, 5, 6, 7] 2 [[3, 3, 3, 4, 44, 4], [5, 5, 4, 5, 6, 7]]