Home java Why when withdrawing an array in the console I see not what...

Why when withdrawing an array in the console I see not what I want?




Learning from time to time Java and faced with this:

Public Static Void Testarray () {
  INT MYARRAY [] = {1, 2, 3, 4, 5};
  System.out.printLN (Myarray);

In the console, I see instead of the expected 12345, this is: [i @ 42e816

When specifying the String type, I see a somewhat modified record: [ljava.lang.string; @ 42e816 (but it is not, I need me to find the amount of numbers in the array, and I probably won’t do it, or I will make with a lot of operations).

In general, how can I withdraw the value of the array, and what would it be in a normal form?

Answer 1, Authority 100%

Because Java does not know what you want. If you want to see an array as if this is a list, then make it a list:

system.out.PrintLN (Arrays.aslist (MYARRAY));

or just with hands:

for (int v: myarray)
  System.out.printLN (V);

Answer 2, AUTHORITY 60%

Tostring () method is not overridden in the class of array in Java – and therefore it works there as well as in the Object class, i.e. Displays a simple name of the object class along with its Hashkode . For a beautiful output of an array, you can use The corresponding array class .

Answer 3, Authority 50%

Use the array.tostring () method, the converting array in the string.

or write a loop that displays the elements of the array.

Answer 4, Authority 10%

array.tostring () method Changes clearly with this task.

In my case

int [] arrnumbers = {99, 567, 22, 45, 1, 91};
System.out.PrintLN (Arrays.Tostring (Arrnumbers));

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions