How to convert String to Integer and int in Java (with Example + Pro Tips)

Here are simple coding tips to convert a given String to int primitive or Integer object in Java with example.

Soma
Javarevisited

--

How to convert String to Integer and int in Java (with Example)

There are two main way to convert a String to int primitive and Integer object in Java :

1) Integer.parseInt(), which takes a String and return an int primitive

2) Integer.valueOf() ,which accept a String and return an Integer object

By the way, if you are new to Java programming language or want to improve Java skills then you can also checkout following best Java courses to get better:

  1. The Complete Java Masterclass (covers Java 17)
  2. Java Programming and Software Engineering Fundamentals Specialization Certificate on Coursera
  3. Java Programming Bootcamp: Zero to Mastery
  4. The Complete Java Programming Masterclass! [Karpado]
  5. CodeGym (learn Java by building Games)

These are my favorite online courses and platforms to learn Java from scratch and also build your Java skills. If you need more advanced courses to take your Java skill to next level you can also see…

--

--