Java中deepToString()和asList()方法的重要性?

数组是一个对象,该对象在连续的内存位置中拥有固定数量的单一类型的值。无论deepToString() asList()方法是静态方法数组 类。 deepToString()方法转换多维数组对字符串和它检查是否一个数组具有元素作为一个数组然后将其转换中的字符串格式数组。的asList()创建具有固定大小,我们不能由添加元素的装置的列表的add() 中返回的列表由方法Arrays.asList() 。该asList() 方法充当数组和列表之间的桥梁,因为asList() 方法返回的列表无法扩展大小。但是可以使用列表的所有其他方法。

Arrays.deepToString()的语法

public static String deepToString(Object[] a)

示例

import java.util.Arrays;
public class DeepToStringTest {
   public static void main(String [] args){
      int[][] array = new int[][] {{1, 2, 3}, {11, 12, 13}, {21, 22,23}};
      System.out.println(Arrays.deepToString(array));
   }
}

输出结果

[[1, 2, 3], [11, 12, 13], [21, 22, 23]]


Arrays.asList()的语法

public static List asList(T... a)

示例

import java.util.Arrays;
public class AsListTest {
   public static void main(String[] args) {
      String[] strArray = {"Welcome", "to", "nhooo"};
      System.out.println(Arrays.asList(strArray));
   }
}

输出结果

[Welcome, to, nhooo]