How to convert a string to int in Java?

To convert a string to int in Java you can use the Integer.parseInt function.

Sample Java

int myInt = Integer.parseInt("1337");


you can also use the parseInt method when using a StringBuffer, but you need to use it like

int myInt = Integer.parseInt(myStringBuffer.toString());

for more informations see the Javadoc parseInt