Java.lang.Long.valueOf() method with examples Last Updated : 05 Dec, 2018 Comments Improve Suggest changes Like Article Like Report Java.lang.Long.valueOf() is a built-in method in Java of lang class that returns a Long object holding the value extracted from a specified String S when parsed with the radix that is given in the second argument. The first argument is interpreted as representing a signed long in the radix specified by the second argument, exactly as if the arguments were given to the parseLong(java.lang.String, int) method. It returns a result that is a Long object that represents the long value specified by the string. Syntax: public static Long valueOf(String s, int radix) throws NumberFormatException Parameters: The method accepts two mandatory parameters: S: This refers to the string which is to be parsed. radix: This refers to the radix which is to be used in interpreting the string S. Return type: The built-in method returns a Long object holding the value represented by the string argument in the specified radix. Errors and Exception: NumberFormatException: If the number does not contain a parsable long the program returns. Below programs illustrate the Java.lang.Long.valueOf() method. Program 1: java // Java program to demonstrate // the java.lang.Long.valueOf() method import java.lang.Math; class Gfg1 { // driver code public static void main(String args[]) { Long l = new Long(10); String str = "45325"; // returns a Long instance representing // the specified string with radix 10 System.out.println("Long instance Value = " + l.valueOf(str, 10)); } } Output: Long instance Value = 45325 Program 2: java // Java program to demonstrate // of java.lang.Long.valueOf() method // NumberFormatException import java.lang.Math; class Gfg1 { // driver code public static void main(String args[]) { Long l = new Long(10); // not a parsable long String str = "gopal"; // returns a Long instance representing // the specified string with radix 10 System.out.println("Long instance Value = " + l.valueOf(str, 10)); } } Output: Exception in thread "main" java.lang.NumberFormatException: For input string: "gopal" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Long.parseLong(Long.java:589) at java.lang.Long.valueOf(Long.java:776) at Gfg1.main(File.java:15) Comment More infoAdvertise with us Next Article Java.lang.Long.valueOf() method with examples gopaldave Follow Improve Article Tags : Misc Java Java-lang package Java-Functions java-Long +1 More Practice Tags : JavaMisc Similar Reads Java lang Long.toOctalString() Method with Examples The Java.lang.Long.toOctalString() function is a built-in function in Java that returns a string representation of the long argument as an unsigned integer in base 8. Syntax: public static int toOctalString(long num) Parameters: The function accepts a single mandatory parameter num, which is to be c 2 min read Number.longValue() method in java with examples The Number.longValue() is an inbuilt method in Java of java.lang package. This method is used to convert any numeric value into a long type. This may involve rounding or truncation.What is longValue()?The longValue() method returns the value of a number after converting it to the long data type. Som 2 min read LongAdder longValue() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.longValue() is an inbuilt method in java that returns the sum(). This method is equivalent to the sum() method. When the object of the class is created its initial value is zero. Syntax: public long longValue 2 min read OptionalLong of(long) method in Java with examples The of(long) method help us to get an OptionalLong object which contains a long value which is passed as a parameter to this method. Syntax: public static OptionalLong of(long value) Parameters: This method accepts a long value as parameter that will be set to the returned OptionalLong object. Retur 1 min read TextStyle valueOf() method in Java with Examples The valueOf() method of TextStyle enum is used to return the enum of this type TextStyle with the specified name. Syntax: public static TextStyle valueOf(String name) Parameters: This method accepts name as the parameter which is the name of the enum constant to be returned. Return value: This metho 1 min read ValueRange of() method in Java with Examples The of() method of ValueRange class helps us to Obtains value range based on parameters passed to it. There are three types of of() methods based on parameters passed to it. of(long min, long max): This method help us to get a fixed value range where the minimum and maximum values are fixed. Syntax: 3 min read Java lang.Long.byteValue() method in Java with Examples java.lang.Long.byteValue() is a built-in function in Java that returns the value of this Long as a byte. Syntax: public byte byteValue() Parameters: The function does not accept any parameter. Return : This method returns the numeric value represented by this object after conversion to byte type. Ex 3 min read FormatStyle valueOf() method in Java with Examples The valueOf() method of a FormatStyle enum is used to get the enum value of this type FormatStyle with the specified name. Syntax: public static FormatStyle valueOf(String name) Parameters: This method accepts a name as the parameter which is the name of the enum constant to be returned. Return valu 1 min read Short longValue() method in Java with Example The java.lang.Short.longValue() method of Short class is a built in method in Java which is used to return the value of the Short object as a long. Syntax ShortObject.longValue() Return Value: It return the value of ShortObject as long. Below is the implementation of longValue() method in Java: Exam 2 min read OptionalLong orElse(long) method in Java with examples The orElse(long) method helps us to get the value in this OptionalLong object. If a value is not present in this OptionalLong, then this method returns the value passed as the parameter. Syntax: public long orElse(long other) Parameters: This method accepts long the value to be returned, if no value 1 min read Like