PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

在Java中,deepToString()和asList()方法的重要性是什么?

王林
王林 转载
2023-08-18 15:13:19 357浏览

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

Arrays.deepToString()的语法

public static String deepToString(Object[] a)

Example

的中文翻译为:

示例

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)

Example

的中文翻译为:

示例

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

输出

[Welcome, to, TutorialsPoint]

以上就是在Java中,deepToString()和asList()方法的重要性是什么?的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除