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);


 Live Demo

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


Integer = 2
Updated on 26-Jun-2020 07:27:21