toString 方法在数组中的使用
对于一个一维数组,他在转换成字符串的时候应该调用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)); } }
结果:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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]]