java - Why won't my array print out correctly? -
this question has answer here:
- what's simplest way print java array? 23 answers
i trying write simple program using code below make single dimensional array can call value using index numbers. using java , eclipse compiler. whenever try debug or run program, full array prints out this: [i@1fa8d3b
.
class array { public static void main(string[] args) { int[] myarray = new int[] {15, 45, 34, 78, 65, 47, 90, 32, 54, 10}; system.out.println("the full array is:"); system.out.println(myarray); system.out.println("the 4th entry in data is: " + myarray[3]); } }
the correct data entry prints out when called though. have tried answers online should do, not find works. starting learn java there simple answer overlooking. if has ideas, appreciative.
java object oriented language. when calling system.out.print(myarray);
in java printing the address of object on heap in memory tostring code it's parent class object
, code shown below contributed comment engfouad, sorry misspeaking. weird string see printed out reference computer uses find data when ask associated variable myarray
.
as stated other answers, print out data of object can use array
class's built in .tostring()
method. print data object instead of object reference.
system.out.println(arrays.tostring(myarray);
correction tostring() of class object: getclass().getname() + "@" + integer.tohexstring(hashcode()). – eng.fouad
mistake above corrected comments, hate give wrong information. misunderstood myself. here api reference see code:
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/object.html#tostring()