java 小贴士

String 转 int,用parse可能会数字转换异常

int foo;try {   foo = Integer.parseInt(myString);}catch (NumberFormatException e){   foo = 0;}

可以这样处理

但是最好这样处理
import com.google.common.primitives.Ints;
int foo = Optional.ofNullable(myString) .map(Ints::tryParse) .orElse(0)

猜你喜欢

转载自www.cnblogs.com/xgkwill/p/12454082.html