So let's have I have the long 12321431
, how would I store that as a String variable inside of Java?
Or let's say 10.15, how would I store it inside a String?
I'm still a newbie at this and I need to do this for file-io purposes.
So let's have I have the long 12321431
, how would I store that as a String variable inside of Java?
Or let's say 10.15, how would I store it inside a String?
I'm still a newbie at this and I need to do this for file-io purposes.
As Robert and Dici mentioned, you can use either of the two variations below:
num.toString(); // string representation
String.valueOf(num); // calls toString
String.valueOf
calls the toString
method of an object. It is now convention to cast using static methods rather than instance methods derived from the most basic Object class. I felt like the underlying code and reasoning was lacking in the other responses.
String strLong = Long.toString(longNumber);