Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question? int[] Vs Integer[]

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Output:
[12, 2, 43, 67, 4, 1, 23]
[I@5224ee


Output varies:
Isn't its answer that Integer class overrides the toString() method and in case of int[], Object class version of toString() used?

How all the values of Integer[] printed when we merely pass an reference variable. What happens inside the toString(), does it do complete traversal or use Iterator or something.

Please help!!!



cmbhatt
 
Omer Haderi
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In the second case you prints the array not the list, so you will get the hashCode of the Object.

here is the toString mystification !
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Omer,








Regards,
cmbhatt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic