File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes int to char[] conversion without String-class? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "int to char[] conversion without String-class?" Watch "int to char[] conversion without String-class?" New topic
Author

int to char[] conversion without String-class?

Till Stoschus
Greenhorn

Joined: May 28, 2009
Posts: 14
Hi,

following code converts an int to a char[] as its string represenation:

Is there an easy way to do this without the "temporary" string so that no further object is created on the heap (only c should be on the heap)?

Thanks!
Tillux
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19230

You can use / 10 and % 10. The biggest issue with this is getting an array that's big enough. java.lang.Integer uses the following code for that:
This code is called as follows:
Using this you should be able to work out the rest.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Till Stoschus
Greenhorn

Joined: May 28, 2009
Posts: 14
Hi Rob,
i played a little with the sourcecode of Integer class. this solved my problem. Thanks!!!
Tillux
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19230

You're welcome.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: int to char[] conversion without String-class?
 
Similar Threads
Converting an INT to a CHAR ?
Get Unicode of a character
Char and Ints
String question
Why call int version,not char version?