2

I'm used to javascript where if for exemple I call :

var tab1 = [0,1,2,3,4];

I can call tab1, and it returns my array content as :

[0,1,2,3,4]

I've noticed in java if I declare an integer array like so :

 int tab1[] = {0,1,2,3};

If I want to print out my array the only way I tought of was doing a loop to print out

tab1[i];

If I call "tab1" alone, I get something like : "[I@15db9742", but why ? What is that piece of code, and why can't we just call variables as loosely ?

Unrefined
  • 77
  • 4
  • 1
    Use `Arrays.toString`. – E_net4 Jun 07 '17 at 20:26
  • 2
    Also https://stackoverflow.com/questions/409784/whats-the-simplest-way-to-print-a-java-array but the other Q&A has a better explanation of why `[I@15db9742` happens. – Radiodef Jun 07 '17 at 20:26
  • I@15db9742 is a memory adress. I can't explain the Why? I can only say because Java. – Alan Jun 07 '17 at 20:28
  • 1
    https://stackoverflow.com/questions/29140402/how-do-i-print-my-java-object-without-getting-sometype2f92e0f4 – Reimeus Jun 07 '17 at 20:32
  • I guess Reimeus beat me to the punch and I didn't notice. I had tried to close this as a duplicate of https://stackoverflow.com/q/29140402/2891664 which has the better explanation I was referring to. – Radiodef Jun 07 '17 at 20:33

0 Answers0