How to Convert Long to String in Java

The data type long is used in programming languages including Java, C++, and C#. A single 64-bit signed integer can be stored in a long constant or variable. So, what does a 64-bit signed integer entail? It helps in breaking down each word from right to left. A full number without a decimal point is called an integer. 1, 24, and 45478 are some examples. Although it may be preceded by a minus (-) mark, “signed” signifies the number can be positive or negative. The number may store 784 or 450,478,7445,569,798,578,614, etc distinct values if it is 64-bit (since one bit is used for the sign). The available integers for the long data type range from  -9223372036854775808 to 9223372036854775807, including 0. Character strings are represented by the String class. This class is used to implement all string literals in Java applications, such as “ABC.”
Strings are immutable once formed, their values cannot be modified. Mutable strings are supported via string buffers. String objects can be shared since they are immutable. So let us start on the tutorial on How to Convert Long to String in Java.


What’s The Approach?


  • Import the java. util package into the class.


  • Now within the main method create a new object of Scanner class, for example, Scanner sc=new Scanner(;


  • Use the Scanner class to get the input from the user.


  • Implement Long.toString(Long_Variable)  to convert the integer to String type


Also Read: How to Reverse a Number in Java using for loop


Java Program to convert Long to String in Java


 * TechDecode Tutorials
 * How to Covert Long to String
import java.util.*;
public class Long_to_String
    public static void main(String args[])
        // Creating an object of Scanner class
        Scanner sc= new Scanner(;
        // taking imput from  the user
        System.out.print("Enter the Long value: ");
        long num=sc.nextLong();
        // converting long to string
        String s = Long.toString(num)  ;
        System.out.println("String is = " + s);


The Output of The above Code

Leave a Reply

Your email address will not be published. Required fields are marked *