# Overloded parseInt(String, int)?

Ahmer Arman
Greenhorn
Posts: 6
Thanks for giving reply of my question. Their is another method with the name of parseInt it has two arguments
parseInt(String, int);
I cannot understand the meaning of int argument in this method.
Again thanks to all who gave me reply.
Ahmer Arman

Dave Vick
Ranch Hand
Posts: 3244
Ahmer
The int argument is the radix that the String integer is in. In other words its base. A String such as "12349" would be base 10 so the parseInt call would be parseInt("12349", 10); .
A String that is a hex representation could be something like "AF", so parseInt would be parseInt("AF", 16);.
Basicaly your telling the method that this String your passing it is in a different base than base 10.
hope that helps

------------------
Dave
Sun Certified Programmer for the Javaï¿½ 2 Platform

Cindy Glass
"The Hood"
Sheriff
Posts: 8521
Well, since any number of classes COULD have a parseInt method - I am going to use my ESP and guess that you are talking about the one in the Integer class.
That method is just saying that if you feed in a number in String format, and you specify that "base" that the number is being displayed in (that would be the second parameter), the method will feed you back the value of that number in base 10.
Of course the String can only use digits that are valid in the base that you say that it is in - so if you say it is in base 5, then the String should only have digits 0,1,2,3 and 4 or else it will throw a NumberFormatException.
The api gives a whole list of examples:

parseInt("0", 10) returns 0
parseInt("473", 10) returns 473
parseInt("-0", 10) returns 0
parseInt("-FF", 16) returns -255
parseInt("1100110", 2) returns 102
parseInt("2147483647", 10) returns 2147483647
parseInt("-2147483648", 10) returns -2147483648
parseInt("2147483648", 10) throws a NumberFormatException
parseInt("99", 8) throws a NumberFormatException
parseInt("Kona", 10) throws a NumberFormatException
parseInt("Kona", 27) returns 411787