in JAVA by
How to do Printing all elements of an array in one println statement in Java

public class Test {

    public static void main(String[] args) {

        int[] a= new int[]{1,2,3};




I expected to take a compile or run-time error.I took an output.It's "[[email protected]".What's the reason of it in Java?

1 Answer

0 votes


That's the default implementation of toString() in Object you're seeing. You can use Arrays.toString for a readable result (make sure to import java.util.Arrays):


Because currently the toString method from Object class is getting invoked, it looks like this

public String toString() {

    return getClass().getName() + "@" + Integer.toHexString(hashCode());


Thats why you see [[email protected]

You can print array content using Arrays.toString which is overloaded method in Arrays class to print the array.


For int[] parameters the method implementation looks like

public static String toString(int[] a) {

    if (a == null)

        return "null";

    int iMax = a.length - 1;

    if (iMax == -1)

        return "[]";

    StringBuilder b = new StringBuilder();


    for (int i = 0; ; i++) {


        if (i == iMax)

            return b.append(']').toString();

        b.append(", ");



Related questions

0 votes
asked Oct 12, 2020 in JAVA by Robindeniel
+2 votes
asked May 13, 2021 in JAVA by rajeshsharma
+2 votes
asked May 13, 2021 in JAVA by rajeshsharma