- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
In Java, printing an array directly (e.g., System.out.println(myArray)) will not display its elements but rather its type and hash code. To output the actual contents, you can use built-in utilities or loops.
Example:
import java.util.Arrays;public class PrintArrayExample {public static void main(String[] args) {int[] numbers = {1, 2, 3, 4, 5};String[] names = {"John", "Mary", "Bob"};// Single-dimensional arraysSystem.out.println(Arrays.toString(numbers)); // [1, 2, 3, 4, 5]System.out.println(Arrays.toString(names)); // [John, Mary, Bob]// Multi-dimensional arraysString[][] deepArray = {{"John", "Mary"}, {"Alice", "Bob"}};System.out.println(Arrays.deepToString(deepArray)); // [[John, Mary], [Alice, Bob]]}}Copied!✕CopyThis uses Arrays.toString() for one-dimensional arrays and Arrays.deepToString() for nested arrays.
Using Loops
For loop:
for (int i = 0; i < numbers.length; i++) {System.out.print(numbers[i] + " ");}Copied!✕CopyEnhanced for-each loop:
for (String name : names) {System.out.println(name);}Copied!✕Copy What's the simplest way to print a Java array? - Stack Overflow
Code sample
String[] array = new String[] {"John", "Mary", "Bob"};System.out.println(Arrays.toString(array));Simplest Method to Print Array in Java - GeeksforGeeks
Jul 23, 2025 · This method takes an array as a parameter and returns a string representation of the array and it can work with all types of arrays like integer arrays, string arrays, etc.
How to Print the Content of an Array in Java | Baeldung
Sep 5, 2024 · Java supports several methods to print the content of a single or multi-dimensional array. In this article, we discussed multiple approaches like …
3 Ways to Print an Array in Java - wikiHow Tech
Sep 13, 2025 · If you are working on Java and have an array with a large amount of data, you may want to print certain elements in order to view them conveniently. …
How Do You Print Out an Array in Java? - agirlamonggeeks.com
Learn how to print out an array in Java quickly and efficiently with easy-to-follow examples. This guide covers different methods including loops, Arrays.toString (), and Java 8 streams. Perfect for …
How to Print or Return an Array in Java - javaspring.net
Jan 16, 2026 · This blog post will provide a comprehensive guide on how to print or return an array in Java, covering fundamental concepts, usage methods, common practices, and best practices.
Top Ways to Print Arrays in Java - sqlpey
Jul 23, 2025 · Discover effective methods to print Java array contents, from standard library functions to Java 8 streams and custom solutions, for both 1D and multi-dimensional arrays.
How to Print Array in Java: Methods and Examples - Intellipaat
Feb 3, 2026 · Java provides multiple methods to print an array. In this guide, you will learn how to print an array in Java using different methods like loops, Streams, and built-in functions
Java Program to Print an Array
In this program, you'll learn different techniques to print the elements of a given array in Java.
How to Print an Array in Java - CodeGym
Feb 10, 2025 · There are a bunch of different ways to print an array in Java. You can use manual traversals using for loops or opt for any standard library methods to do the same.