by Sai gowtham

Convert a string to long in Java

To convert a string to long, we can use the Long.valueOf() method in Java.

Here is an example:

String str = "1234854";

long number = Long.valueOf(str);

System.out.println(number);

Output:

1234854

You can also use new Long() constructor to convert a string to long.

String str = "1234854";

long number = new Long(str);

System.out.println(number);  // 1234854

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
130,921 students enrolled
21 hours of video content
View Course