Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App

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)  

G

gopaldave
Improve
Article Tags :
  • Misc
  • Java
  • Java-lang package
  • Java-Functions
  • java-Long
Practice Tags :
  • Java
  • Misc

Similar Reads

    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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences