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

Sample Java

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

tip

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

One thought on “How to convert a string to int in Java?”

Leave a Reply