EN
Java - how to print array?
1
answers
0
points
What is the easiest way to print an array in Java? How can I get the proper output?
I tried this:
public class Example {
private static int[] myArray = {1, 2, 3};
public static void main(String[] args) {
System.out.println(myArray);
}
}
but I got this:
[I@e580929
1 answer
0
points
Import:
import java.util.Arrays;
and use Arrays.toString()
method to print the array, so your code would look like this:
import java.util.Arrays;
public class Example {
private static int[] myArray = {1, 2, 3};
public static void main(String[] args) {
System.out.println(Arrays.toString(myArray));
}
}
Output:
[1, 2, 3]
0 comments
Add comment