Home > Java > javaTutorial > What is the importance of deepToString() and asList() methods in Java?

What is the importance of deepToString() and asList() methods in Java?

王林
Release: 2023-08-18 15:13:19
forward
653 people have browsed it

An array is an object that holds a fixed number of values ​​of a single type in contiguous memory locations. The deepToString() and asList() methods are both static methods of the Arrays class. deepToString() method converts a multidimensional array to a string and checks if the array has elements as an array and then converts the array to string format. asList() Creates a list with a fixed size, which means we cannot add to the list returned by Arrays.asList() via the add() method element. The asList() method acts as a bridge between arrays and lists because the list returned by the asList() method cannot be extended in size, but all other methods of lists can be used.

The syntax of Arrays.deepToString()

public static String deepToString(Object[] a)
Copy after login

Example

’s Chinese translation is:

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(<strong>Arrays.deepToString</strong>(array));
   }
}
Copy after login

Output

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

The syntax of Arrays.asList()

public static List asList(T... a)
Copy after login

Example

’s Chinese translation is:

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));
   }
}
Copy after login

Output

[Welcome, to, TutorialsPoint]
Copy after login

The above is the detailed content of What is the importance of deepToString() and asList() methods in Java?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template