Returns a string representation of the “deep contents” of the specified array. If the array contains other arrays as elements, the string representation contains their contents and so on. This method is designed for converting multidimensional arrays to strings. The simple toString() method works well for simple arrays, but doesn’t work for multidimensional arrays. This method is designed for converting multi-dimensional arrays to strings.
public static String deepToString(Object arr) arr - An array whose string representation is needed This function returns string representation of arr. It returns "null" if the specified array is null.
Let us suppose that we are making a 2-D array of 3 rows and 3 column. 2 3 4 5 6 7 2 4 9 If use deepToString() method to print the 2-D array, we will get string representation as :- [[2,3,4], [5,6,7], [2,4,9]]
Printing multidimensional Array
[[99, 151], [30, 5]]
toString() vs deepToString()
toString() works well for single dimensional arrays, but doesn’t work for multidimensional arrays.
[practice.geeksforgeeks.org, quiz.geeksforgeeks.org] [[I@15db9742, [I@6d06d69c]
Note : We can use a loop to print contents of a multidimensional array using deepToString().
deepToString() works for both single and multidimensional, but doesn’t work single dimensional array of primitives
[practice.geeksforgeeks.org, quiz.geeksforgeeks.org] [10, 20, 30, 40]
This article is contributed by Mohit Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java.util.LinkedList.offer(), offerFirst(), offerLast() in Java
- Java.util.concurrent.RecursiveTask class in Java with Examples
- Java Deprecated API Scanner tool (jdepscan) in Java 9 with Examples
- Java.lang.Short toString() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java.util.LinkedList.peek() , peekfirst(), peeklast() in Java
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java.util.concurrent.RecursiveAction class in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java.util.concurrent.Phaser class in Java with Examples