Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing all elements of an array in one println statement in Java [duplicate]

Tags:

java

arrays

public class Test {

    public static void main(String[] args) {

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

        System.out.println(a);


    }
}

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

like image 502
Furkan Avatar asked Dec 09 '22 05:12

Furkan


1 Answers

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):

System.out.println(Arrays.toString(a));
like image 78
August Avatar answered May 06 '23 11:05

August