try { String testStr = "3"; int testInt = Integer.parseInt(testStr); System.out.println(testInt); }catch(NumberFormatException nfe) { System.out.println(nfe); } try是必须是,如果没有的话,无论转换对还是错,都不会报错。
把String转换成int
最新推荐文章于 2023-12-15 15:08:57 发布
try { String testStr = "3"; int testInt = Integer.parseInt(testStr); System.out.println(testInt); }catch(NumberFormatException nfe) { System.out.println(nfe); } try是必须是,如果没有的话,无论转换对还是错,都不会报错。