String 转 Integer
时间: 2024-04-20 17:04:35 浏览: 22
可以使用Integer.parseInt(String s)方法将字符串s转换为整数类型的Integer。例如:
```java
String s = "123";
int i = Integer.parseInt(s);
```
这样i的值就是123。如果字符串s不是一个合法的整数,例如包含非数字字符,那么该方法将会抛出NumberFormatException异常。
相关问题
String 转Integer
把一个 String 转成 Integer 的方法可以使用 Integer.parseInt(),例如:
```
String str = "123";
int num = Integer.parseInt(str);
```
这样,字符串 "123" 就被转换成了整数类型的 123。需要注意的是,如果字符串中包含的不是数字,那么调用 parseInt() 方法就会抛出一个 NumberFormatException 异常。
string 转 integer
可以使用Integer.parseInt(String s)方法将字符串s转换为整数类型的Integer。例如:
```java
String s = "123";
int i = Integer.parseInt(s);
```
这样i的值就是123。如果字符串s不是一个合法的整数,例如包含非数字字符,那么该方法将会抛出NumberFormatException异常。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)