1、使用integer类中的parseInteger方法
int intvalue= Integer.parseInteger(intString);
- 1
例如:要将字符串“111”转换成数字111
int a=Integer.parseInteger("111");//a=111
- 1
其实很多数字类都支持从String转换成 parse成数值:
byte b = Byte.parseByte("111");
short s = Short.parseShort("111");
int i = Integer.parseInt("111");
long l = Long.parseLong("111");
float f = Float.parseFloat("1.11");
double d = Double.parseDouble("1.11");
- 1
- 2
- 3
- 4
- 5
- 6
2、数字转化成字符串类型
各种数字类型转换成字符串型:
String s = String.valueOf( value); // 其中 value 为任意一种数字类型。
- 1
字符串型转换成各种数字类型:
1 String s = "122";
2 byte b = Byte.parseByte( s );
3 short t = Short.parseShort( s );
4 int i = Integer.parseInt( s );
5 long l = Long.parseLong( s );
6 Float f = Float.parseFloat( s );
7 Double d = Double.parseDouble( s );