Java.lang.Long.decode() Method


Advertisements


Description

The java.lang.Long.decode() method decodes a String into a Long.It accepts decimal, hexadecimal, and octal numbers.

Declaration

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

public static Long decode(String nm) throws NumberFormatException

Parameters

nm − This is the String to decode.

Return Value

This method returns a Long object holding the long value represented by nm.

Exception

NumberFormatException − if the String does not contain a parsable long.

Example

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

package com.tutorialspoint;

import java.lang.*;

public class LongDemo {

   public static void main(String[] args) {

      Long l = new Long(10);

      String str = "57820";
      
      /* returns Long object holding the long value represented by 
         string str */
      System.out.println("Number = " + l.decode(str)); 
   }
}  

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

Number = 57820

java_lang_long.htm

Advertisements