Integer.parseInt()

+1 Bacon+Tuna S · February 5, 2015
My friend is in school taking java, he  recently show me something like this  Integer.parseInt(), what is this really mean? He is taking  java in school and i didn't take it because of buckysroom, any recommendation for me please?!

Post a Reply

Replies

Oldest  Newest  Rating
0 Jasmeet Singh · February 5, 2015
its used to convert (parse) values of any data type to integer type!
in java if we use the BufferedReader to input some value, it will be of string type by default so to get an integer value we parse it.


BufferedReader br = new BufferedReader(new InputStremReader(System.in));   
String s = br.readLine();                                                                                                                                                                                                                                                      
int rollno = Integer.parseInt(s); //will parse the string s to its integer equivalent
0 Nicholas Eason · February 5, 2015
What that method does, is it takes a String and makes it an Integer.

Here's an example:
String numOfWhatever = "52"

//This method takes an integer as a parameter
//You can't call howManyWhatever(numOfWhatever) because numOfWhatever is a String
//So, you need to make the String and Integer.

int whateverCount = Integer.parseInt(numOfWhatever);

//This makes whateverCount be equal to numOfWhatever, except whateverCount is an Integer.
//Now you can use whateverCount in the howManyWhatever() method.

howManyWhatever(whateverCount);
  • 1

Java / Android Development

127,926 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator