Avatar ·

How to simply and beautifully output an array in Java? Problem with toString()

Hello everyone! I just started learning Java and I have a seemingly simple problem. I need to output the contents of an array to the screen. I wrote this code: ```java int[] numbers = {1, 2, 3, 4, 5}; System.out.println(numbers); ``` But instead of the expected `[1, 2, 3, 4, 5]`, I get some strange string like `[I@1a2b3c4d`. I understand that this is probably a hash code or object address, but I need the actual contents of the array! I tried with both string arrays and integer arrays — the result is always the same. For example, for `String[] names = {"Alice", "Bob", "Charlie"};` the output also looks like an incomprehensible string like `[Ljava.lang.String;@5f184fc6`. Please tell me how to properly output an array in Java? Is there a simple way to make the result look nice?