how do you convert a string into a long.
for int you
int i = 3423; String str; str = str.valueOf(i);
so how do you go the other way but with long.
long lg; String Str = "1333073704000" lg = lg.valueOf(Str);
Java – Convert String to long using Long. Long. valueOf(String): Converts the String to a long value. Similar to parseLong(String) method, this method also allows minus '-' as a first character in the String.
We can convert long to String in java using String. valueOf() and Long. toString() methods.
This is a common way to do it:
long l = Long.parseLong(str);
There is also this method: Long.valueOf(str);
Difference is that parseLong
returns a primitive long
while valueOf
returns a new Long()
object.
The method for converting a string to a long is Long.parseLong. Modifying your example:
String s = "1333073704000"; long l = Long.parseLong(s); // Now l = 1333073704000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With