How to Convert a String to an Long in Java ? Last Updated : 26 Feb, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 ConversionInput: " 9876543210"Output: 9876543210Program Convert String to Long in JavaThe Most basic method we can come up with to convert String to Long in Java is using Constructor: Java // Java Program to Convert String to Long // Using Constructor of Long class import java.io.*; import java.util.*; // Driver Class class GFG { // Main driver method public static void main(String[] args) { // Custom input string String str = "9876543210"; System.out.println("String : " + str); // Converting above string to long // using Long(String s) constructor Long num = new Long(str); // Printing the above long value System.out.println("Long : " + num); } } 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. Comment More infoAdvertise with us Next Article How to Convert Char to String in Java? E eswarbe06sp Follow Improve Article Tags : Java Java Programs java-Long Java-String-Programs strings Java Examples +2 More Practice Tags : JavaStrings Similar Reads How to Convert a String to an Numeric in Java? In Java programming, there are situations in which we must convert a string of numeric characters into one of the following data types: double, float, long, or int. To execute arithmetic operations and other numerical calculations, this conversion is necessary. We will look at how to convert a strin 2 min read How to Convert Char to String in Java? In this article, we will learn how to Convert Char to String in Java. If we have a char value like 'G' and we want to convert it into an equivalent String like "G" then we can do this by using any of the following three listed methods in Java. Using toString() method of Character classUsing valueOf( 5 min read How to Convert a String to a Character in Java? String and char are fundamental and most commonly used datatypes in Java. A String is not a primitive data type like char. To convert a String to char in Java, we have to perform character-based operations or have to process individual characters.In this article, we will learn how to convert a Strin 3 min read Java Program to Convert String to Long To convert a String to Long in Java, we can use built-in methods provided by the Long class. In this article, we will learn how to convert String to Long in Java with different methods. Example:In the below example, we use the most common method i.e. Long.parseLong() method to convert a string to a 3 min read Java Program to Convert Long to String The long to String conversion in Java generally comes in need when we have to display a long number in a GUI application because everything is displayed in string form. In this article, we will learn about Java Programs to convert long to String. Given a Long number, the task is to convert it into a 4 min read Java Program to Convert int to long Given a number of int datatype in Java, your task is to write a Java program to convert this given int datatype into a long datatype. Example: Input: intnum = 5 Output: longnum = 5 Input: intnum = 56 Output: longnum = 56 Int is a smaller data type than long. Int is a 32-bit integer while long is a 6 2 min read Like