[英]Java8 Optional ignore NumberFormatException
I am converting a Optional<String>
to Integer
by .map(Integer::parseInt)
. 我正在通过
.map(Integer::parseInt)
将Optional<String>
转换为Integer
。 Is there a way to avoid NumberFormatException
if string can't be parsed as int
? 如果无法将字符串解析为
int
是否可以避免NumberFormatException
?
I want to avoid try/catch
statement for this. 我想避免对此的
try/catch
语句。
使用Google Guava Ints.tryParse
map(Ints::tryParse)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.