Java.lang.Long.valueOf() Method


Description

The java.lang.Long.valueOf(String s) method returns a Long object holding the value of the specified String s.

Declaration

Following is the declaration for java.lang.Long.valueOf() method

public static Long valueOf(String s) throws NumberFormatException

Parameters

s − This is the string to be parsed.

Return Value

This method returns a Long object holding the value represented by the string argument.

Exception

NumberFormatException − If the string cannot be parsed as a long.

Example

The following example shows the usage of java.lang.Long.valueOf() method.

package com.tutorialspoint;

import java.lang.*;

public class LongDemo {

   public static void main(String[] args) {

      Long l = new Long(30);
   
      String str = "57695";
      // returns a Long instance representing the specified string
      System.out.println("Value = " + l.valueOf(str));
   }
}  

Let us compile and run the above program, this will produce the following result −

Value = 57695
java_lang_long.htm
Advertisements