java tutorial - How to convert string to integer in java - java programming - learn java - java basics - java for beginners
Learn Java - Java tutorial - str to int1 - Java examples - Java programs
Using Integer.parseInt()
- The Integer.parseInt() method is used primarily in parsing a String method argument into Integer object.
- The Integer.parseInt method is a very convenient Java API to transform a user input in String format into a more robust object type which in this case the Integer.
- Make a note that the parseInt method of Integer class is static hence it must be accessed statically. Mean to say that we would calling this method.
Syntax
Sample Code:
Output:
Learn Java - Java tutorial - str to int2 - Java examples - Java programs
Java convert string to int Using Integer.valueOf()
- Integer.valueOf() Returns an Integer object holding the value extracted from the specified String when parsed with the radix given by the second argument.