Open links in new tab
    • Work Report
    • Email
    • Rewrite
    • Speech
    • Title Generator
    • Smart Reply
    • Poem
    • Essay
    • Joke
    • Instagram Post
    • X Post
    • Facebook Post
    • Story
    • Cover Letter
    • Resume
    • Job Description
    • Recommendation Letter
    • Resignation Letter
    • Invitation Letter
    • Greeting Message
    • Try more templates
  1. 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 arrays
    System.out.println(Arrays.toString(numbers)); // [1, 2, 3, 4, 5]
    System.out.println(Arrays.toString(names)); // [John, Mary, Bob]

    // Multi-dimensional arrays
    String[][] deepArray = {{"John", "Mary"}, {"Alice", "Bob"}};
    System.out.println(Arrays.deepToString(deepArray)); // [[John, Mary], [Alice, Bob]]
    }
    }
    Copied!

    This 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!
    • Enhanced for-each loop:

    for (String name : names) {
    System.out.println(name);
    }
    Copied!
    Feedback
  2. What's the simplest way to print a Java array? - Stack Overflow

    We could have used Arrays.toString() to print one dimensional array and Arrays.deepToString() for multi-dimensional arrays.
    Overview

    2398 In Java, arrays don't override toString(), so if you try to print one directly, you get the className + '@' + the hex of the hashCode of the array, as defined by Object.toString(): But usually, we'd actually want something more like [1, 2, 3, 4, 5]. W…

    37 Answers

    Since Java 5 you can use Arrays.toString() or Arrays.deepToString() for arrays within arrays. Note that the Object version calls.toString() on each object in the array. The output is even decorated in the exact way you're asking. Simple Array: What if w…

    Arrays.toString

    As a direct answer, the solution provided by several, including @Esko, using the Arrays.toString and Arrays.deepToStringmethods, is simply the best.

    Java 8 - Stream.Collect (Joining()), Stream.Foreach

    Below I try to list some of the other methods suggested, attempting to improve a little, with the most notable addition being the use of the Stream.collect operator, using a joining Collector, to mimic what the String.join is doing. Starting with Java 8, o…

    Code sample

    String[] array = new String[] {"John", "Mary", "Bob"};
    System.out.println(Arrays.toString(array));
  3. 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.

  4. 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 …

  5. 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. …

  6. 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 …

  7. 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.

  8. 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.

  9. 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

  10. Java Program to Print an Array

    In this program, you'll learn different techniques to print the elements of a given array in Java.

  11. 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.