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

后端 未结 7 835
小鲜肉
小鲜肉 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);
    
    0 讨论(0)
提交回复
热议问题