java - Advantages of Integer.parseInt() over Integer constructor -
we can directly following conversion:
string s="123"; int a=new integer(s);
then advantages using integer.parseint()
method?
integer constructor internally calls parseint
, returns int
. if call parseint
directly avoid autoboxing (constructor returns integer
).
public integer(string s) throws numberformatexception { this.value = parseint(s, 10); }
also using parseint
can parse string using different radix 10. instance:
int hex = integer.parseint("ff", 16); // 255 int bin = integer.parseint("10", 2); // 2
Comments
Post a Comment