• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert int value to a char array in java?  RSS feed

 
Taylor Shell
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i return num into a char array?
This is my code so far, its returning the handle and not the array.


 
Stephan van Hulst
Saloon Keeper
Posts: 7991
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what's the problem?
 
Taylor Shell
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's printing out the handle
 
Stephan van Hulst
Saloon Keeper
Posts: 7991
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm assuming you mean when you call System.out.println() with the resulting value. Please post all relevant code when you have a problem.

println() converts an object to a string using toString(). The toString() method doesn't work on arrays the way you expect it to. Instead, you should use Arrays.toString().
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:println() converts an object to a string using toString()...

<nitpick>
Not quite correct. It uses String.valueOf(Object), which in turn calls toString() if the supplied object isn't null.
</nitpick>

@Taylor: However, everything else Stephan said is correct.

Winston
 
Stephan van Hulst
Saloon Keeper
Posts: 7991
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, true
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taylor Shell wrote:It's printing out the handle
That might not be a handle; it includes the hashcode but that is not necessarily the memory location of the array.

Please check the details of System.out#print(char[]), because that might print out the contents of the array. Try this sort of code:-Did you call toString on the array?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!