programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Meaning and Use of "parseint" method

rajnish patel
Ranch Hand
Posts: 56
Hi,
I am a java beginner and I just saw this method
I also tried myself but I can't understand logic of it.
I don't know how the output is generated.
So can anyone explain me meaning of it and when it is used ??

Also tell me that when a simple parseint(String x) method is used.

Waiting for kind reply.

OUTPUT :-
124
228
292
1092
172
364
444

Robert Lippens
Greenhorn
Posts: 27
I recommend taking a look at Oracle's webdocs on the Integer class.

When you use two parameters for the parseInt method, the first takes your string, tries to parse it, and the second is a radix - which is apparently the number of unique digits used to represent a number. So, "444" parsed using 5 unique digits is apparently 124. Unsure of the exact math but that is what the javadocs seem to say. Without the second parameter, the method simply takes your string and turns it into an int.

see http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html

rajnish patel
Ranch Hand
Posts: 56
Robert Lippens wrote:I recommend taking a look at Oracle's webdocs on the Integer class.

When you use two parameters for the parseInt method, the first takes your string, tries to parse it, and the second is a radix - which is apparently the number of unique digits used to represent a number. So, "444" parsed using 5 unique digits is apparently 124. Unsure of the exact math but that is what the javadocs seem to say. Without the second parameter, the method simply takes your string and turns it into an int.

see http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html

sorry but sir, I am still not clear about how its parsed and how 5 digits are passed and how output is generated.
Can you please explain simple parseint() method ??

Saif Asif
Ranch Hand
Posts: 440
The second parameter is your Radix, i.e your base whether is needs to be parsed using base decimal , octal , hex or another you like.

do post back for any further queries.

rajnish patel
Ranch Hand
Posts: 56
Saif Asif wrote:The second parameter is your Radix, i.e your base whether is needs to be parsed using base decimal , octal , hex or another you like.

do post back for any further queries.

Thank you for replying sir,
I got satisfactory answer.
By the way, I also want to know why it is used ??

Campbell Ritchie
Marshal
Posts: 56600
172

rajnish patel
Ranch Hand
Posts: 56
Campbell Ritchie wrote:Dictionary Link.

I wanted to know in terms of programming and also why is it used !!

Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
• 1
Because sometimes you have a number in the form of text (as a string), for example if a user entered it in a text box, and you need to convert it to an int, so that the computer can do calculations with it.

rajnish patel
Ranch Hand
Posts: 56
Jesper de Jong wrote:Because sometimes you have a number in the form of text (as a string), for example if a user entered it in a text box, and you need to convert it to an int, so that the computer can do calculations with it.

Great sir,
I thought that it would be like this and I was true.
Thank you so much sir.

 It is sorta covered in the JavaRanch Style Guide.