无异常的字符串数字转换函数

来源:互联网 发布:西岐网络 彭永辉 编辑:程序博客网 时间:2024/04/27 20:07

From Apache Commons Lang:

// returns defaultValue if the string cannot be parsed.int i = org.apache.commons.lang.math.NumberUtils.toInt(s, defaultValue);

From Google Guava:

// returns null if the string cannot be parsed.Integer i = com.google.common.primitives.Ints.tryParse(s);

There is no need to write your own methods to parse numbers without throwing exceptions.

原创粉丝点击