参考: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的更多相关文章

  1. [LeetCode] String to Integer (atoi) 字符串转为整数

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  2. Integer.valueof(String s)和Integer.parseInt(String s)的具体区别是什么?

    Integer.valueof(String s)和Integer.parseInt(String s)的具体区别是什么? Integer.valueof(String s)是将一个包装类是将一个实际 ...

  3. No.008:String to Integer (atoi)

    问题: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input ca ...

  4. LeetCode 7 -- String to Integer (atoi)

    Implement atoi to convert a string to an integer. 转换很简单,唯一的难点在于需要开率各种输入情况,例如空字符串,含有空格,字母等等. 另外需在写的时候 ...

  5. [LeetCode] 8. String to Integer (atoi)

    Implement atoi to convert a string to an integer. public class Solution { public int myAtoi(String s ...

  6. 【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); ///////////// ...

  7. Integer.parseInt(String s) 和 Integer.valueOf(String s) 的区别

    通过查看java.lang.Integer的源码可以发现, 它们最终调用的都是 /** * Parses the string argument as a signed integer in the ...

  8. java 13-4 Integer和String、int之间的转换,进制转换

    1.int类型和String类型的相互转换 A.int -- String 推荐用: public static String valueOf(int i) 返回 int 参数的字符串表示形式. B. ...

  9. Integer.valueOf(String) 方法之惑

    本文由 ImportNew - 靳禹 翻译自 stackoverflow.欢迎加入翻译小组.转载请见文末要求. 有个仁兄在 StackOverflow 上发起了一个问题,是这么问的: “ 我被下面的代 ...

  10. String to Integer

    Implement function atoi to convert a string to an integer. If no valid conversion could be performed ...

随机推荐

  1. openoffice在连接时有错误,无法连接上

    openoffice在连接时有错误,无法连接上 报如下错误: java.net.ConnectException: connection failed: socket,host=localhost,p ...

  2. (转) MapReduce Design Patterns(chapter 5 (part 2))(十)

    Replicated Join Pattern Description 复制join是一种特殊的join,用于一个大数据和许多小数据集map端执行的情况. Intent 这种模式能够消除reduce阶 ...

  3. iOS开发之如何应对苹果app的ipv6时代?

    WWDC2015苹果宣布在ios9支持纯IPv6的网络服务,并且要求2016年提交到app store的应用必须兼容纯IPv6的网络,要求适配的系统版本是ios9以上(包括ios9). 一 背景介绍 ...

  4. linux另一种安装方式

    linux中其实没有“安装”的概念:安装就是设下路径,拷贝文件,复制文件,运行下脚本这些(windows也应该如此) 法一.把bin运行路径设成环境变量 法二.ln一下,例如: 解压下载的文件: ta ...

  5. 【剑指offer】二叉树中和为某一值的路径,C++实现

    原创文章,转载请注明出处! 博客文章索引地址 1.题目 输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径由结点和有向边组成,从根结点到叶节点. // 二叉树结点的定义 st ...

  6. 【剑指offer】二叉搜索树转双向链表,C++实现

    原创博文,转载请注明出处! # 题目 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建任何新的结点,只能调整树中结点指针的指向. 二叉树节点的定义 struct TreeNod ...

  7. 【机器学习】集成学习之sklearn中的xgboost基本用法

    原创博文,转载请注明出处!本文代码的github地址    博客索引地址 1.数据集 数据集使用sklearn自带的手写数字识别数据集mnist,通过函数datasets导入.mnist共1797个样 ...

  8. [svn]显示日志很慢 点击文件查看更改记录也贼慢

    特此记录,防止以后忘记. 解决办法: 在 C:\Windows\System32\drivers\etc (win7) 中加入 即可 亦或将代码的url中pc名字改为ip地址也可以解决问题 对文件夹点 ...

  9. python 除法

  10. WEB服务器都在做哪些工作?

    作为WEB开发人员,我们肯定应该要知道WEB服务器都在做哪些工作,这里简单列举一下,有时间然后详细说明. (1)建立连接——接受一个客户端连接. (2)接收请求——从网络中读取一条 HTTP 请求报文 ...