Proper way to avoid parseInt throwing a NumberFormatException for input string: “”

后端 未结 7 882
小鲜肉
小鲜肉 2020-12-06 09:53

When I run parseInt:

Integer.parseInt(myString);

it throws:

NumberFormatException: For input string: \"\"

7条回答
  •  不知归路
    2020-12-06 10:54

    I don't know why was I searching for this but here's the easy way:

    int test=str.isEmpty()?0:Integer.parseInt(str);
    

提交回复
热议问题