Skip to main content

Java – Convert String to long

We can useLong.parseLong() and Long.valueOf() to convert String to long.

Using Long.parseLong()

Convert to long primitive.

Using Long.valueOf()

Convert to long Object.

How to handle invalid number?

If String contains an invalid number. It will be thrown the NumberFormatException. It can be thrown or handled it.


Related Post

3306total visits,2visits today

RSS
Follow by Email
Facebook
Facebook
Google+
http://mydevgeek.com/java-convert-string-long
Twitter