参考: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. 转:android Support 兼容包详解

    本文转自stormzhang的ANDROID SUPPORT兼容包详解 背景 来自于知乎上邀请回答的一个问题Android中AppCompat和Holo的一个问题?, 看来很多人还是对这些兼容包搞不清 ...

  2. eclipse 生成发布的apk (signed zipalign过程)

    在发布apk到appstore过程中,上传的apk需要先signed(先生成keystore和key)并zipalign.可按照以下步骤来完成:1. 创建一个keystore和key(右键eclips ...

  3. Android Studio 默认 debug.keystore , apk打包,keystore.jks文件生成,根据keystore密钥获取SHA1安全码

    参考资料: https://blog.csdn.net/nimasike/article/details/51457229 https://www.cnblogs.com/zhangqie/p/643 ...

  4. 关于swagger文档的使用方法

    引言 最近在后台开发的时候,使用swagger2进行前后台接口文档的声明.由此遇见的一些问题,写下来给自己复习. 参考: https://blog.csdn.net/xupeng874395012/a ...

  5. svn问题解答

    一.svn在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted 原因,工作队列被占用,只需在 ...

  6. LeetCode 819. Most Common Word

    原题链接在这里:https://leetcode.com/problems/most-common-word/description/ 题目: Given a paragraph and a list ...

  7. wpf中如何在xaml中绑定cs中类的属性

    cs代码:/// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWin ...

  8. 【DUBBO】 Dubbo生成的设配类

    package com.alibaba.dubbo.rpc;import com.alibaba.dubbo.common.extension.ExtensionLoader;public class ...

  9. [MEF]第02篇 MEF的导入导出契约

    一.演示概述此演示介绍了如何为Export指定导出的协议名和类型,以及如何为Import指定导入的协议名和类型,只有确保导出和导入的协议名和类型相匹配了,才能注入成功,否则注入就会失败.相关下载(屏幕 ...

  10. ecmall页面空白解决方案(转)

    页面空白解决方案: ------------------------------------------------------------------------------------------ ...