In Java, String to Integer Conversion is not always effective as the size of the String can overpass Integer. In this article, we will learn the method provided by the Long class or by using the constructor of the Long class.
Example of String to Long Conversion
Input: " 9876543210"
Output: 9876543210
Program Convert String to Long in Java
The Most basic method we can come up with to convert String to Long in Java is using Constructor:
OutputString : 9876543210
Long : 9876543210
Explanation of the above program:
- String str is the String which we want to Convert to Long.
- String str size can be short as Short Integer or Long as Long Integer.
- Long object num is initiated and the string value is passed as parameter.
- String Object value is now passed to Long Integer which has now the same value that of Integer.
- Now we get the result num.