java.lang.String valueOf(long l)
Description :
This java tutorial shows how to use the valueOf(long l) method of String class of java.lang package. This method returns a string representation of long data type. This is the same method as Long.toString(long).
Method Syntax :
public static String valueOf(long l)
Parameter Input :
DataType | Parameter | Description |
---|---|---|
long | l | method parameter which we are interested to get the string equivalent |
Method Returns :
The String valueOf() method with argument long returns a new String object which corresponds to the string representation of the method argument.
Compatibility Version :
Since the beginning
Exception :
None
Discussion :
The string valueOf(long l) method is simply to get a String equivalent of int method parameter. This method be statically accessed which means we should call the method like String.valueOf(long l).
Java Code Example :
This example source code demonstrates the use of valueOf(long l) of String class. Below are different examples of getting a value of long. As you would noticed we have used the unboxing functionality to transform a Long object into long primitive datatype and then get the string equivalent using the valueof method.
package com.javatutorialhq.java.tutorial.string; /* * Java example source code to get the value of primitive long data type */ public class StringValueOfLong { public static void main(String[] args) { // primitive long declaration long val = 1; // Object of Long data type Long valueLong = 100l; System.out.println(String.valueOf(val)); System.out.println(String.valueOf(valueLong)); System.out.println(String.valueOf(1234567)); } }
Sample Output :
Running the valueOf() method example source code of String class will give you the following output
Exception Scenario :
N/A