← Back to list

Why Does System.out.println(array1) Print [I@4f023edb in Java?

As a Java beginner, you may expect an array to print its elements. However, when you run the following code:

Akash S · 2026-06-19 01:33 · 4 claps · 1.7 min read
#arrays #javaprogrammingtips #java #datastrucutre #programming
Open on Medium ↗
Wiki topics: 💻 · Programming

Why Does System.out.println(array1) Print [I@4f023edb in Java?

As a Java beginner, you may expect an array to print its elements. However, when you run the following code:

int[] array1 = new int[4];
array1[0] = 10;
System.out.println(array1);

You might see an output like:

[I@4f023edb

Let’s understand why this happens.

Step 1: Creating the Array

int[] array1 = new int[4];

This statement creates an integer array of size 4.

+----+----+----+----+
| 0  | 0  | 0  | 0  |
+----+----+----+----+

The variable array1 does not store the actual values. It stores a reference (memory address) to the array object.

After assigning:

array1[0] = 10;

The array becomes:

+----+----+----+----+
| 10 | 0  | 0  | 0  |
+----+----+----+----+

Step 2: Passing the Array to println()

When Java executes:

System.out.println(array1);

the array reference is passed to the println() method.

Internally, Java selects:

println(Object x)

because arrays are objects.

Step 3: Converting the Object to Text

The println() method cannot directly print objects.

Therefore, Java internally converts the object into a String.

Conceptually:

System.out.println(array1);

becomes:

System.out.println(array1.toString());

Step 4: The toString() Method

Arrays do not provide their own implementation of toString().

Therefore, they inherit the default implementation from the Object class.

The default implementation behaves approximately like this:

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

Step 5: Understanding [I@4f023edb

The output:

[I@4f023edb

can be broken down as follows:

PartMeaning[Indicates an arrayIRepresents int type@Separator4f023edbHash code in hexadecimal

Therefore:

[I@4f023edb

means:

“This is an integer array object with a specific hash code.”

Why Doesn’t Java Print the Elements?

Java arrays do not override the toString() method.

As a result, Java prints object information instead of the actual contents.

Correct Way to Print Array Elements

Use the Arrays.toString() method.

import java.util.Arrays;
int[] array1 = new int[4];
array1[0] = 10;
System.out.println(Arrays.toString(array1));

Output:

[10, 0, 0, 0]

Now Java prints the actual contents of the array.

Key Takeaways

  • Arrays are objects in Java.
  • System.out.println(array1) prints the array reference information.
  • println() internally calls toString().
  • Arrays use the default Object.toString() implementation.
  • Use Arrays.toString() to print array elements.

Conclusion

The output [I@4f023edb is not an error. It is Java's default way of representing an array object. Understanding this behavior helps developers learn important concepts such as objects, references, method overloading and the toString() method, which are commonly asked in Java interviews and used in real-world applications.


메타데이터
post_id
9106514ff598
slug
why-does-system-out-println-array1-print-i-4f023edb-in-java-9106514ff598
url
https://medium.com/@itakash557/why-does-system-out-println-array1-print-i-4f023edb-in-java-9106514ff598
canonical_url
https://medium.com/@itakash557/why-does-system-out-println-array1-print-i-4f023edb-in-java-9106514ff598
author_url
https://medium.com/@itakash557
status
ok
fetched_at
2026-06-26 03:39:16