java.util.Arrays class has many useful methods to perform the operations on the arrays. deepToString() method is one such method. Arrays.deepToString() method is used to get the string representation of multidimensional arrays. This method returns the deep contents of the specified array. If the specified array contains other arrays as it’s elements then it returns the contents of those arrays also.
Below example shows how to use deepToString() method to print the contents of the multidimensional arrays.
If you want to print the contents of one dimensional arrays, then use Arrays.toString() method or normal for loop or enhanced for loop. You can also use Arrays.deepToString() method to print the contents of one dimensional arrays. But, If you want to print the contents of multidimensional arrays, instead of nesting multiple for loops, use Arrays.deepToString() method. It is the easiest method to print the contents of multidimensional arrays.
Below example shows how to use deepToString() method to print the contents of the multidimensional arrays.
OUTPUT:
If you want to print the contents of one dimensional arrays, then use Arrays.toString() method or normal for loop or enhanced for loop. You can also use Arrays.deepToString() method to print the contents of one dimensional arrays. But, If you want to print the contents of multidimensional arrays, instead of nesting multiple for loops, use Arrays.deepToString() method. It is the easiest method to print the contents of multidimensional arrays.
No comments:
Post a Comment