new Integer(text).intValue()的用法
2015-11-01 15:23
405 查看
parseInt(String s )方法是类Integer的静态方法,它的作用就是将形参 s 转化为整数,比如:
Interger.parseInt("1")=1;
Integer.parseInt("20")=20;
Integer.parseInt("324")=324;
当然,s 表示的整数必须合法,不然是会抛异常的。
valueOf(String s )也是Integer类的静态方法,它的作用是将形参 s 转化为Integer对象,
什么是Integer对象,Integer就是基本数据类型int型包装类,就是将int包装成一个类,这样在很多场合下是必须的。如果理解不了,你就认为int是Integer的mini版,好用了很多,但也丢失了一些功能,好了,看代码:
Interger.valueOf("123")=Integer(123)
这时候Integer(123)就是整数123的对象表示形式,它再调用intValue()方法,就是将123的对象表示形式转化为基本数据123
这个是类型的转换,转化的结果是int
int a=new Integer("3").intValue();
int b=new Integer(3).intValue();
System.out.println(a+1);
System.out.println(b+1);
从上例,楼主应该可以看出。它可以重载两个构造函数
这是从integer转向int 的时候会用到intValue;
当然如果你想从字符串转向int也可以换另外的方法
int a =Integer.parseInt(Text);
int a=Integer.valueOf(Text);
其中Text表示字符串
Interger.parseInt("1")=1;
Integer.parseInt("20")=20;
Integer.parseInt("324")=324;
当然,s 表示的整数必须合法,不然是会抛异常的。
valueOf(String s )也是Integer类的静态方法,它的作用是将形参 s 转化为Integer对象,
什么是Integer对象,Integer就是基本数据类型int型包装类,就是将int包装成一个类,这样在很多场合下是必须的。如果理解不了,你就认为int是Integer的mini版,好用了很多,但也丢失了一些功能,好了,看代码:
Interger.valueOf("123")=Integer(123)
这时候Integer(123)就是整数123的对象表示形式,它再调用intValue()方法,就是将123的对象表示形式转化为基本数据123
这个是类型的转换,转化的结果是int
int a=new Integer("3").intValue();
int b=new Integer(3).intValue();
System.out.println(a+1);
System.out.println(b+1);
从上例,楼主应该可以看出。它可以重载两个构造函数
这是从integer转向int 的时候会用到intValue;
当然如果你想从字符串转向int也可以换另外的方法
int a =Integer.parseInt(Text);
int a=Integer.valueOf(Text);
其中Text表示字符串
相关文章推荐
- InterView common question
- ios学习之苹果官方文档的学习(UIFocusUpdateContext方面)
- hadoop 之 InputFormat类 --- KeyValueTextInputFormat 实例
- Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel 打表数学
- InputSplit—>RecordReder—>map(key,value,context)的过程解析
- POJ 1947 Rebuilding Roads(树形DP)
- NGUI简单的UI功能操作
- IOS-UITableView上的纯代码实现
- cf#328-B. The Monster and the Squirrel-水题+数学规律
- HDU 5531 Rebuild 相切的圆们
- EasyUI - DataGrid 组建 - [ 样式功能 ]
- handler更新UI主线程
- uestcoj Huatuo's Medicine 1226 (简单题)
- uva 1612——Guess
- Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel
- priority_queue的用法
- IDDFS--UESTC - 577 分数拆分
- Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel(数学规律)
- Codeforces Round #328 (Div. 2)_B. The Monster and the Squirrel
- Codeforces Round #328 (Div. 2)_B. The Monster and the Squirrel