Convert string to int with Java

In Java to convert a string to int requires the class java.lang.Integer.

Primitive int

The returned result will be a primitive integer.

String number = "1234567890";
int result = Integer.parseInt(number);

Integer object

The returned result will be an integer object.

String number = "1234567890";
Integer result = Integer.valueOf(number);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>