将String类型转换

文章参考转载自:https://jingyan.baidu.com/article/d71306359c8aa813fdf47514.html

转成int型

1、使用Integer类中的parseInt()方法。

private void addExpert(Map params) {
        int number = Integer.parseInt(params.get("expertNumber"));
        String expertName = "";
}

2、使用Integer类中的valueOf()和intValue()方法。
都是Integer的静态方法:
Integer.parseInt(str)是把一个数字字符串转化成int类型的数据
Integer.valueOf(str or num) 是把一个数字或者一个字符串转化为Integer类型的数据

转成其他类型

3、使用正则表达式判断String是否为int整型or浮点型数据。动态选择方法转换数据。

如何将string转换为int类型

4、String 转 double 的方法。

如何将string转换为double类型

5、String 转 Float 的方法。

如何将string转换为Float类型

6、注意,当String为Long数据类型时,即String长度超过int的长度时转换int数据类型时会出现错误的结果。

如何将string转换为Long类型

你可能感兴趣的:(将String类型转换)