• Post Reply Bookmark Topic Watch Topic
  • New Topic

I am trying to return an array, and it is printing out random characters?  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my code:




It's printing out this (the second line):
 
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

You need to print out the array like you're doing in lines 9-12. What you're seeing there is a different kind of representation of the array, which is not meant for humans.
 
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively you could use the java.util.Arrays.toString(..) method get the contents of the array as a String (in human readable form) and output that.
 
Marshal
Posts: 56606
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look up Object#toString and you find that is how it is implemented. Arrays do not have an overridden toString method, so they give exactly the same output.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!