Convert long to String in Java

Convert long to String in Java Example describes about Convert long to String in Java.

Long class helps to wrap the primitive type value of long in an object.

In addition, Long class provides several useful methods for dealing with long primitives.

When we need to Convert long to String in Java, we can use Long.toString(long l) method of Long class, This method will convert the long to String.

If you need a Long type in lieu of primitive long, you can use the method Long.valueOf(long l). This method will convert the long primitive to Long type

Convert long To String In Java

public class ConvertLongToString {

 
public static void main(String[] args) {
  
   
long f = 1040;
  
   
// convert long to String type
   
System.out.println(Long.toString(f));
  
   
// convert long primitive to Long type
   
System.out.println(Long.valueOf(f));
  
 
}
}
Output
1040

1040










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