Converting a String into an Int in Java 👨‍💻1️⃣

👏 THANKS: I appreciate the claps readers give because it takes me some time to write these free articles.

It’s one of the simple things that’s always hard to remember. Here’s how:

1.) Convert String to Int using Integer.parseInt() 💻

Use the “Integer.parseInt()” command like in the following example:

String exampleString = "1";
Integer exampleInteger = Integer.parseInt(exampleString);

Done! You can do the next step to double check, but this should already work.

2.) (Verification) Check your code works on this online editor ✅

Use the following free online Java compiler:

Run the following code to verify it works:

String exampleString = "1";
Integer exampleInteger = Integer.parseInt(exampleString);
System.out.println(exampleInteger);

That’s it!

Thanks for reading! Please leave a clap like my other readers if this helped 😊

--

--

26K+ Reads ✍🏼 Co-founder & CTO @Connect Earth. Ex-Amazon 👨‍💻 Passionate about sustainability and software👌 Views are all my own.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nicolas Carmont

26K+ Reads ✍🏼 Co-founder & CTO @Connect Earth. Ex-Amazon 👨‍💻 Passionate about sustainability and software👌 Views are all my own.