intValue、parseInt、valueOf 方法区别及其使
2015-10-27 22:18
525 查看
intValue是把Integer对象类型变成int的数据类型; parseInt是吧String 变成int的数据类型; Valueof是吧给定的参数转化成对象类型; |
// 第一个不常用 Integer a_=new Integer(123); // a_是Integer类型 int a=a_.intValue(); // 转化为int类型 System.out.println(a); String b = "123"; // 一个string int b_=Integer.parseInt(b); // 把string转化成int System.out.println(b_); int c_=123; String c=String.valueOf(c_); System.out.println(c); 其中:由于valueOf方法是调用parseInt方法,并且由Integer.valueOf()方法来转换。所以parseInt稍微比valueOf快一点。
public static Integer valueOf(String s, int radix) throws NumberFormatException {
return Integer.valueOf(parseInt(s,radix));
}
public static Integer valueOf(int i) {
if(i >= -128 && i <= IntegerCache.high)
return IntegerCache.cache[i + 128];
else
return new Integer(i);
}
相关文章推荐
- jsp request 对象详解
- request属性 request.getAttribute()
- getServletConfig().getServletContext().getRequestDispatcher("xxx.jsp")的用法
- Exchange工具15—dnsquery
- hdoj 2227 Find the nondecreasing subsequences 【树状数组优化dp】
- EasyUI - DataGrid 组建 - [ 组件加载和分页 ]
- serialVersionUID作用
- UIBezierPath 画圆弧(角度问题)
- (CCPC F题)UESTC 1220 The Battle of Guandu (最短路)
- codeforces 589H - Tourist Guide(dfs)
- 用KVC中setValuesForKeysWithDictionary:方法模型化一个字典
- 【UIKit-32-1】UIDataDetectors 文本号码邮箱链接自动识别
- 【UIKit-54-1】UIInterface-系统的颜色与字体
- 关于自定义UITableViewCell报错问题
- 【UIKit-100-1】UIStepper
- 【UIKit-98-1】UISlider
- 【UUIKit-51-1】UIImageView-创建与属性
- 解决方案--duilib中edit获得鼠标焦点后右边框被覆盖
- 解决方案--duilib中edit获得鼠标焦点后右边框被覆盖
- CF 590B Chip 'n Dale Rescue Rangers(二分)