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.
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.
Long instance Value = 45325
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)
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Split() String method in Java with examples
- Java.util.Collections.rotate() Method in Java with Examples
- DelayQueue add() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Dictionary size() Method in Java with Examples
- Constructor getAnnotatedReturnType() method in Java with Examples
- Constructor getAnnotatedReceiverType() method in Java with Examples
- Java Math random() method with Examples
- Collections checkedMap() method in Java with Examples
- Duration from(TemporalUnit) method in Java with Examples
- LocalDate plusDays() Method in Java with Examples
- LocalTime toNanoOfDay() method in Java with Examples
- LocalTime toSecondOfDay() method in Java with Examples
- FloatBuffer compact() method in Java With Examples
- ShortBuffer order() Method in Java with Examples
- Scanner nextFloat() method in Java with Examples
- Java 8 | BigInteger divideAndRemainder() method with Examples
- ByteArrayInputStream available() method in Java with Examples
- ThaiBuddhistDate now(ZoneId) method in Java with Examples
- Map Values() Method in Java With Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.