字符串转整型小记录

1.使用Intger.parseInt(String)方法:

当字符串不是正确的数值(如“Q”)的时候, Integer.parseInt()方法可能会抛出NumberFormatException的异常 。

其他的数据类型也有类似的方法,如Float.parseFloat()  和 Double.parseDouble() 。

2.使用Integer.valueOf() 方法:

该方法会忽略无意义的0(比如00000004)最后输出为4。

出现错误也会抛出NumberFormatException的异常 。

posted @ 2021-12-19 11:18  夏莱发电厂的Sensei  阅读(66)  评论(0)    收藏  举报