Integer-->String String-->Integer
参考:http://blog.csdn.net/wangjolly/article/details/18354457
crane:
String str="123";
int a=0;
Integer b = null;
String--->int
<1> a=Integer.parseInt(str); //parseInt(String s) 将字符串参数作为有符号的十进制整数进行解析。
将字符串参数作为有符号的十进制整数进行解析。
-->
<2> a=Integer.valueOf(str).intValue(); //valueOf(String s) 返回保存指定的 String 的值的 Integer 对象。
如果不能转换,则报异常:java.lang.NumberFormatException
String--->Integer
b=Integer.valueOf(str); //valueOf(String s) 返回保存指定的 String 的值的 Integer 对象。
int--->String
<1> str=a+"";
<2> str=Integer.toString(a); //toString(int i) 返回一个表示指定整数的 String 对象
<3> str=String.valueOf(a);// valueOf(int i) 返回 int 参数的字符串表示形式。
Integer--->String
b=new Integer(2);
str=b.toString(); //toString() 返回一个表示该 Integer 值的 String 对象。
int--->Integer
<1> b=Integer.valueOf(a); //valueOf(int i) 返回一个表示指定的 int 值的 Integer 实例。
<2> b=new Integer(a);
<3> b=a; //装箱 (编译器自动执行Integer.valueOf(a))
Integer--->int
<1> b=new Integer(2);
a=b.intValue(); // intValue() 以 int 类型返回该 Integer 的值。
<2> a=b; //拆箱 (编译器自动执行b.intValue())
Integer-->String String-->Integer的更多相关文章
- [LeetCode] String to Integer (atoi) 字符串转为整数
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...
- Integer.valueof(String s)和Integer.parseInt(String s)的具体区别是什么?
Integer.valueof(String s)和Integer.parseInt(String s)的具体区别是什么? Integer.valueof(String s)是将一个包装类是将一个实际 ...
- No.008:String to Integer (atoi)
问题: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input ca ...
- LeetCode 7 -- String to Integer (atoi)
Implement atoi to convert a string to an integer. 转换很简单,唯一的难点在于需要开率各种输入情况,例如空字符串,含有空格,字母等等. 另外需在写的时候 ...
- [LeetCode] 8. String to Integer (atoi)
Implement atoi to convert a string to an integer. public class Solution { public int myAtoi(String s ...
- 【java基础学习一】int[]、Integer[]、String[] 排序( 正序、倒叙)、去重
调用: //重复项有9.5.1.2 int[] ints = new int[]{9,4,7,8,2,5,1,6,2,5,9,1}; arrayIntTest(ints); ///////////// ...
- Integer.parseInt(String s) 和 Integer.valueOf(String s) 的区别
通过查看java.lang.Integer的源码可以发现, 它们最终调用的都是 /** * Parses the string argument as a signed integer in the ...
- java 13-4 Integer和String、int之间的转换,进制转换
1.int类型和String类型的相互转换 A.int -- String 推荐用: public static String valueOf(int i) 返回 int 参数的字符串表示形式. B. ...
- Integer.valueOf(String) 方法之惑
本文由 ImportNew - 靳禹 翻译自 stackoverflow.欢迎加入翻译小组.转载请见文末要求. 有个仁兄在 StackOverflow 上发起了一个问题,是这么问的: “ 我被下面的代 ...
- String to Integer
Implement function atoi to convert a string to an integer. If no valid conversion could be performed ...
随机推荐
- obj-y,obj-m 区别
obj-y:把由foo.c 或者 foo.s 文件编译得到foo.o 并连接进内核.obj-m: 则表示该文件作为模块编译.除了y.m以外的obj-x 形式的目标都不会被编译. 除了obj-形式的目标 ...
- React-Native进阶_5.导航 Naviagtion
有这样一个组件 他可以控制页面跳转 返回,在移动端叫做导航控制器, 在RN中叫路由 我们使用的 react-native-navigation 是一个开源组件库介绍:A complete nativ ...
- React-Native基础_2.样式Style
2.样式Style 基本使用 方式1 直接在View 上面写style 内容 <View style={{ backgroundColor: '#07811d', flex: 1 }}> ...
- NSPort
NSPort是一个描述通信通道的抽象类.通信发生在两个NSPort对象之中,这两个NSPort对象通常属于不同的进程或任务.分发对象系统使用NSPort对象来返回或发送NSProtMessage对象. ...
- 胖AP基本配置:
配置思路: 先创建wlan并广播ssid 进入射频子接口封装用户vlan 进入射频口关联wlan 注意:03 多个无线信号配置 注:在把AP改为 ap-mode fat后不能退出特权模式,不然需要 ...
- rest-framework框架 -- 认证权限流程源码
认证权限 解析BaseAuthentication源码 # 做认证权限 from rest_framework import exceptions from ..models import * cla ...
- 【剑指offer】05替换空格,C++实现
1.题目 # 请实现一个函数,将一个字符串中的空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 2.思路 # 从头到尾遍历字 ...
- threeJs中旋转位移等操作坐标系
1.场景中的立方体.圆柱等三维模型的位置属性.平移方法参照Scene对象的世界坐标系 2.场景中立方体.圆柱等的三维模型的角度属性.旋转方法参照模型自身的模型坐标系
- 20179223《Linux内核原理与分析》第十二周学习笔记
Return-to-libc 攻击实验 一.实验描述 缓冲区溢出的常用攻击方法是用 shellcode 的地址来覆盖漏洞程序的返回地址,使得漏洞程序去执行存放在栈中 shellcode.为了阻止这种类 ...
- DVD项目
package sy.com.cn;import java.util.*; public class DvdWorker { public static void main(String[]args) ...