Home » Java programming language

Java Integer class decode() method with example

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

Integer class decode() method

  • decode() method is available in java.lang package.
  • decode() method is used to decode the given String value into an integer 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 an Integer.
    NumberFormatException: In this exception, if the given string parameter does not have a parsable integer.


    public static Integer decode(String str);


  • String str – represents the string to be decoded.

Return value:

The return type of this method is Integer, it returns the Integer holding an integer value represented by the argument of String type.


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

public class DecodeOfIntegerClass {
    public static void main(String[] args) {
        // Variables initialization
        int i = 100;
        String str = "20";

        // Integer object initialized with "int" value
        Integer value1 = new Integer(i);

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

        // It returns an Integer object holding the integer value 
        // denoted by the given String argument by calling 
        // value1.decode(str)
        Integer result = value1.decode(str);

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


value1: 100
value1.decode(str) :20


Comments and Discussions



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

© some rights reserved.