Java Program to convert a string into a numeric primitive type using Integer.valueOf()

Java 8Object Oriented ProgrammingProgramming

The Integer.valueOf() method is used in Java to convert a string into a numeric primitive type.

Let’s say the following is our string.

String str = "989";

To convert it into Integer primitive type, use Integer.valueOf()

Integer.valueOf(str)

Let us see the complete example to convert a string to Integer primitive type.

Example

 Live Demo

public class Demo {
    public static void main(String[] args) {
       String str = "989";
       System.out.println(Integer.valueOf(str));
    }
}

Output

989
raja
Published on 12-Dec-2018 10:32:13
Advertisements