Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.5k points)
I got a simple question in Java: How can I convert a String that was obtained by Long.toString() to long?

1 Answer

0 votes
by (46k points)

Try Long.parseLong():

 Long.parseLong("0", 10)        // returns 0L

 Long.parseLong("473", 10)      // returns 473L

 Long.parseLong("-0", 10)       // returns 0L

 Long.parseLong("-FF", 16)      // returns -255L

 Long.parseLong("1100110", 2)   // returns 102L

 Long.parseLong("99", 8)        // throws a NumberFormatException

 Long.parseLong("Hazelnut", 10) // throws a NumberFormatException

 Long.parseLong("Hazelnut", 36) // returns 1356099454469L

 Long.parseLong("999")          // returns 999L

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 26, 2019 in Java by Shubham (3.9k points)

Browse Categories

...