• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Convert int value to a char array in java?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Saloon Keeper
Posts: 15489
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what's the problem?
 
Taylor Shell
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's printing out the handle
 
Stephan van Hulst
Saloon Keeper
Posts: 15489
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 15489
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, true
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic