Write Java program to Convert a Long to String


This is a Java program that demonstrates how to convert a long value to a string using the Long.toString() method. In this program, a long variable a is initialized with the value of 1423461. Then, a null string variable str is declared.

The program then uses the System.out.println() method to print the value of the long variable a. Next, the Long.toString() method is called, passing in the long variable a as an argument. This method returns a string representation of the long value. The returned string is then assigned to the str variable.

Finally, the program uses the System.out.println() method to print the string representation of the long value that was stored in the str variable.

Source Code

public class LongToString
{
	public static void main(String args[])
	{
		long a = 1423461;
		String str = null;
		System.out.println("Integer Values : " + a);
 
		//convert long to string
		str = Long.toString(a);
		System.out.println("Long to String : " + str);
	}
}

Output

Integer Values : 1423461
Long to String : 1423461