| 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.
|
 |
 |
|
|
subject: int to char[] conversion without String-class?
|
|
|