Java Program to Convert Long to String

Write a Java program to convert long to string. In Java, we can use String.valueOf and Long.toString() methods to convert long to string. This Java example accepts the user input long value and converts it to string using the sting valueOf function.

package NumPrograms;

import java.util.Scanner;

public class longToString1 {
	private static Scanner sc;	
	
	public static void main(String[] args) {
		
		sc= new Scanner(System.in);	
		
		System.out.print("Enter Any Long Value =  ");
		long l1 = sc.nextLong();
		
		String s1 = String.valueOf(l1);

		System.out.println("Long To String = " + s1);
	}
}
Java Program to Convert Long to String

Java program to convert long to string using the Integer toString method.

package NumPrograms;

import java.util.Scanner;

public class longToString2 {
	private static Scanner sc;	
	
	public static void main(String[] args) {
		
		sc= new Scanner(System.in);	
		
		System.out.print("Enter Any Long Value =  ");
		long l1 = sc.nextLong();
		
		String s1 = Long.toString(l1);

		System.out.println("Long To String = " + s1);
	}
}
Enter Any Long Value =  9877263723
Long To String = 9877263723

Let me use both the available Java options to convert long to string in one example.

package NumPrograms;

import java.util.Scanner;

public class longToString3 {
	private static Scanner sc;	
	
	public static void main(String[] args) {
		
		sc= new Scanner(System.in);	
		
		System.out.print("Enter Any Long Value =  ");
		long l1 = sc.nextLong();
		
		String s1 = String.valueOf(l1);	
		String s2 = Long.toString(l1);

		System.out.println("Long To String = " + s1);
		System.out.println("Long To String = " + s2);
	}
}
Enter Any Long Value =  32565432
Long To String = 32565432
Long To String = 32565432