快速打印多维数组的数据元素列表
想要快速打印一个一维数组的数据元素列表,只需要调用Arrays.toString()
方法,就像这样:
public static void main(String[] args) {
int[] c = new int[3];
System.out.println(Arrays.toString(c));
}
想要快速打印一个多维数组的数据元素列表,只需要调用Arrays.deepToString()
方法,就像这样:
public static void main(String[] args) {
int[][] c = new int[3][3];
System.out.println(Arrays.deepToString(c));
}
或者这样:
public static void main(String[] args) {
int[][][] c = new int[3][3][3];
System.out.println(Arrays.deepToString(c));
}
当然,四维数组类似。
参考资料:
[1] Cay S.Horstmann 著,林琪 苏钰涵等译.Java核心技术 卷1(原书第11版).北京:机械工业出版社,2020:87.