- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
Java Arrays - deepToString() Method
Description
The Java Arrays deepToString(Object[]) method 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 string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space).
Declaration
Following is the declaration for java.util.Arrays.deepToString() method
public static String deepToString(Object[] a)
Parameters
a − This is the array whose string representation to return
Return Value
This method returns a string representation of a.
Exception
- NA
Example 1
The following example shows the usage of Java Arrays deepToString(Object[]) method. In this example, we've created one array of Strings and printed the string version of it using deepToString() method.
package com.tutorialspoint; import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { //initializing an string array String[] stringArr = { "tuts","point" }; System.out.println("Deep String version: "); // printing value System.out.println(Arrays.deepToString(stringArr)); } }
Output
Let us compile and run the above program, this will produce the following result −
Deep String version: [tuts, point]
Example 2
The following example shows the usage of Java Arrays deepToString(Object[]) method. In this example, we've created one array of Integers and printed the string version of it using deepToString() method.
package com.tutorialspoint; import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { //initializing an integer array Integer[] intArr = { 1, 2 }; System.out.println("Deep String version: "); // printing value System.out.println(Arrays.deepToString(intArr)); } }
Output
Let us compile and run the above program, this will produce the following result −
Deep String version: [1, 2]
Example 3
The following example shows the usage of Java Arrays deepToString(Object[]) method. In this example, we've created one array of Student objects and printed the string version of it using deepToString() method.
package com.tutorialspoint; import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { //initializing an Student array Student[] studentArr = { new Student(1, "Julie"), new Student(2, "Robert"), new Student(3, "Adam") }; System.out.println("Deep String version: "); // printing value System.out.println(Arrays.deepToString(studentArr)); } } class Student { int rollNo; String name; Student(int rollNo, String name){ this.rollNo = rollNo; this.name = name; } @Override public String toString() { return "[ " + this.rollNo + ", " + this.name + " ]"; } }
Output
Let us compile and run the above program, this will produce the following result −
Deep String version: [[ 1, Julie ], [ 2, Robert ], [ 3, Adam ]]