Java Program to decode string to integer


The method Integer.decode() decodes a string to an integer. It returns an Integer object holding the int value represented by the passed string value.

Note − It accepts decimal, hexadecimal, and octal number.

Let’s say the following is our string.

String val = "2";

The following is how you can decode the string to integer.

Integer myInt = Integer.decode(val);

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      String val = "2";
      Integer myInt = Integer.decode(val);
      System.out.println("Integer = " + myInt);
   }
}

Output

Integer = 2

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

366 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements