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

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

When I run parseInt:

Integer.parseInt(myString);

it throws:

NumberFormatException: For input string: \"\"

7条回答
  •  隐瞒了意图╮
    2020-12-06 10:37

    Integer.parseInt(String) doesn't accept non-numeric input, including nulls and empty strings.

    Either guard against that like you suggested, or catch the NFE.

提交回复
热议问题