Home >Java >javaTutorial >What is the importance of deepToString() and asList() methods in Java?
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.
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(<strong>Arrays.deepToString</strong>(array)); } }
[[1, 2, 3], [11, 12, 13], [21, 22, 23]]
public static List asList(T... a)
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]
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!