Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Khoa Dang
Courses Plus Student 72 Pointsinteger question
What is the purpose of Integer.parseInt ? why don't we just type int age = 30; instead of int age = Integer.parseInt("30"); they have the same result right?
1 Answer

Jeremy Hill
29,567 PointsYou would only need to use Integer.parseInt(); if the argument being passed in was of a different type. Here is an example:
String number = console.readLine("Please type a number: ");
int total = Integer.parseInt(number);
Doing it this way would convert the String that was passed in by the user into an int.
Jason Anders
Treehouse Moderator 145,826 PointsJason Anders
Treehouse Moderator 145,826 PointsHi Khoa,
Could you add a little more context to your question. There could be multiple uses for
Integer.parseInt()
, but it wouldn't be used in the example you provided. If you are setting an integer, it would just beint age = 30;
... that's it.If you could provide so more examples or a reference to where in the courses you noticed this, we could shed some better light on the subject. :)