Home » Java programming language

Java Long class decode() method with example

Long class decode() method: Here, we are going to learn about the decode() method of Long class with its syntax and example.
Submitted by Preeti Jain, on October 12, 2019

Long class decode() method

  • decode() method is available in java.lang package.
  • decode() method is used to decode the given String value into a Long value.
  • decode() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also we will not get an error.
  • decode() method may throw a NumberFormatException at the time of decoding a String to a Long.
    NumberFormatException: In this exception, if the given string parameter does not have a parsable integer.

Syntax:

    public static Long decode(String str);

Parameter(s):

  • String str – represents the String to decode.

Return value:

The return type of this method is long, it returns the Long holding a long value represented by the argument of String type.

Example:

// Java program to demonstrate the example 
// of decode(String str) method of Long class

public class DecodeOfLongClass {
    public static void main(String[] args) {
        // Variables initialization
        long l = 100;
        String str = "20";

        // Long object initialized with "long" value
        Long ob1 = new Long(l);

        // Display ob1 result
        System.out.println("ob1: " + ob1);

        // It returns an Long object holding the long value 
        // denoted by the given String argument by calling 
        // ob1.decode(str)
        Long result = ob1.decode(str);

        // Display result
        System.out.println("ob1.decode(str) :" + result);
    }
}

Output

ob1: 100
ob1.decode(str) :20





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.