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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -