Java Program to decode string to integer

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 10-Dec-2018 08:12:42
Advertisements