How to simply and beautifully print an array in Java to the screen?
Hello everyone! I just started learning Java and encountered what seemed like a simple task: printing the contents of an array to the console. But everything went wrong.
I have this code:
public class Main {\n public static void main(String[] args) {\n int[] numbers = {1, 2, 3, 4, 5};\n System.out.println(numbers);\n }\n}\n
I expected to see something like [1, 2, 3, 4, 5], but instead some gibberish is printed to the console: [I@1b6d3586. What is this strange output? I tried different arrays (strings, numbers) — the result is always similar: [Ljava.lang.String;@2f92e0f4 and so on.
I read that the array has a toString() method, but it doesn't work as expected either. I tried Arr