[For input string: ""] java solutions encountered error problem

Java developers who do, your life, at least once or repeatedly encountered [For input String: ""] this error problem because usually appear in a string coerced to numeric types when misstatements.

such as:

String yanggb = "";
int num = Integer.parseInt(yanggb);

This code will be reported [For input String: ""] error message.

This time the solution is very simple, just do the type conversion when it null and deal with it.

String yanggb = "";
int num = Integer.parseInt(StringUtil.isNotEmpty(yanggb) ? yanggb : "0");

Pay special attention to making the string type conversion when numeric type, otherwise this problem may occur.

 

"Life is so varied it seems, you never what unexpected turn certainly will not occur after one thing law."

Guess you like

Origin www.cnblogs.com/yanggb/p/12331056.html