Arrays.deepToString()

For multi-dimensional arrays, the Arrays.deepToString() method provides a convenient way to print the contents.

Java




/*package whatever //do not write package name here */
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
        int[][] matrix
            = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
        System.out.println(Arrays.deepToString(matrix));
        // Output: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
    }
}


25 Interesting Facts about Arrays in Java

Java arrays are the workhorses of many programs, offering a structured way to store and manipulate data. While arrays are a fundamental concept, there are intriguing facts that developers may not be aware of for Java Arrays. In this blog post, we’ll explore 25 interesting facts about arrays in Java, shedding light on their nuances and capabilities.

Table of Content

  • 1. Zero-Based Indexing:
  • 2. Fixed Size:
  • 3. Primitive and Object Types:
  • 4. Reference Variables:
  • 5. Dynamic Initialization:
  • 6. Array Copying:
  • 7. Varargs and Arrays:
  • 8. Arrays.asList():
  • 9. Array Equality:
  • 10. The Enhanced for Loop:
  • 11. Cloneable Interface:
  • 12. Arrays.deepToString():
  • 13. Arrays.sort():
  • 14. Parallel Array Sorting:
  • 15. Jagged Arrays:
  • 16. Memory Efficiency:
  • 17. Array Initialization Shortcut:
  • 18. Array Length Attribute:
  • 19. ArrayDeque vs. Arrays:
  • 20. Arrays.fill():
  • 21. Garbage Collection:
  • 22. Array Reflection:
  • 23. Arrays and Generics:
  • 24. Array Performance:
  • 25. Arrays in Streams:

Similar Reads

1. Zero-Based Indexing:

Arrays in Java use zero-based indexing, meaning the first element is accessed with index 0, the second with index 1, and so on....

2. Fixed Size:

...

3. Primitive and Object Types:

The size of an array in Java is fixed upon creation and cannot be changed afterward...

4. Reference Variables:

...

5. Dynamic Initialization:

Arrays in Java can store both primitive data types (int, char, etc.) and objects....

6. Array Copying:

...

7. Varargs and Arrays:

Arrays are objects in Java, and when declared, a reference variable is created....

8. Arrays.asList():

...

9. Array Equality:

While the size of an array is fixed, its elements can be dynamically initialized....

10. The Enhanced for Loop:

...

11. Cloneable Interface:

Java provides methods like System.arraycopy() and Arrays.copyOf() for efficient copying of arrays....

12. Arrays.deepToString():

...

13. Arrays.sort():

Varargs (variable-length argument lists) in Java are implemented using arrays....

14. Parallel Array Sorting:

...

15. Jagged Arrays:

The Arrays.asList() method facilitates the conversion of arrays to Lists....

16. Memory Efficiency:

...

17. Array Initialization Shortcut:

Arrays do not override the equals() method in Java’s Object class....

18. Array Length Attribute:

...

19. ArrayDeque vs. Arrays:

The enhanced for loop introduced in Java 5 simplifies array traversal....

20. Arrays.fill():

...

21. Garbage Collection:

Arrays implement the Cloneable interface, allowing developers to create a copy of an array using the clone() method....

22. Array Reflection:

...

23. Arrays and Generics:

For multi-dimensional arrays, the Arrays.deepToString() method provides a convenient way to print the contents....

24. Array Performance:

...

25. Arrays in Streams:

The Arrays.sort() method efficiently sorts arrays....

Contact Us