Languages
[Edit]
EN

Java - convert String to long

4 points
Created by:
Broncono
466

In Java, we can convert String to long in couple of different ways.

Short solutions:

1. Using Long.parseLong()

Edit

Output:

2. Using Long.valueOf()

Edit

Output:

3. String to long with sign + or -

Edit

Output:

4. Example of java.lang.NumberFormatException

Edit

Output:

Both methods:

  • Long.parseLong("123")
  • Long.valueOf("123")

will throw java.lang.NumberFormatException if we try to parse anything else then:
digits or '+', '-' as first character.

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java - String conversion

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join