Programming-Idioms

History of Idiom 22 > diff from v85 to v86

Edit summary for version 86 :
[Java] Avoid constructing a new Integer object by directly calling parseInt

Version 85

2019-12-11, 23:22:43

Version 86

2019-12-13, 09:06:29

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Illustration

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Illustration
Extra Keywords
int base conversion
Extra Keywords
int base conversion
Code
int i = new Integer(s).intValue();
Code
int i = Integer.parseInt(s);
Comments bubble
This will throw NumberFormatException if s does not contain a parsable integer
Comments bubble
This will throw NumberFormatException if s does not contain a parsable integer
Doc URL
https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#Integer%28java.lang.String%29
Doc URL
https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#parseInt(java.lang.String)