Integer和int的区别
来源:互联网 发布:matlab编程二分法求根 编辑:程序博客网 时间:2024/06/06 09:50
1. int 是基本数据类型,直接存数值,而integer是对象,用一个引用指向这个对象
2.int 初始化时默认值是0,而integer初始化时默认值是null
初始化 int i =1;Integer i= new Integer(1);(要把integer 当做一个类看);但由于有了自动装箱和拆箱,使得对Integer类也可使用:Integer i= 1; Integer 是一个类,是int的扩展,定义了很多的转换方法类似的还有:float Float;double Double;string String等,而且还提供了处理
int
类型时非常有用 的 其他一些常量和方法举个例子:当需要往ArrayList,HashMap中放东西时,像int,double这种内建类型是放不进去的,因为容器都是装 object的,这 是就需要 这些内建类型的外覆类了。 3. 声明为Integer的变量需要实例化,而声明为int的变量不需要实例化
4 . Java中int和Integer关系
1.int是基本的数据类型;
2.Integer是int的封装类;
3.int和Integer都可以表示某一个数值;
4.int和Integer不能够互用,因为他们两种不同的数据类型;
举例说明
ArrayList al=new ArrayList();
int a=2;
Integer b=new Integer(a);
al.add(a);//不可以
al.add(b);//可以
附加:字符串转换为基本类型
int num1=new Integer("10");
int num 2=Integer.parseInt("123");
基本类型转换为字符串
String s3=String.valueOf(66);
String s2=Integer.toString(100);
阅读全文
0 0
- int 和 Integer 的区别
- int 和 Integer 的区别
- int和Integer的区别
- int和Integer的区别
- int 和 integer的区别
- Integer和int的区别
- Integer 和 int 的区别
- int和integer的区别
- int和Integer的区别
- int 和integer的区别
- int 和 Integer的区别
- int 和integer的区别
- int 和integer的区别
- Integer和Int的区别
- int 和integer的区别
- int 和integer的区别
- Int 和integer的区别
- int 和Integer的区别
- test
- java swing实现的拼图小游戏项目源码
- 逆波兰表达式 —— 递归专题
- WPF界面控件Essential Studio for WPF发布2017 v4版本
- markdown查看本地图片(github)
- Integer和int的区别
- 怎么找到win10由于删除文件后清空回收站的文件
- 忘记myql的root的密码,如何修改?
- Redis五种数据类型的相关命令
- Spring学习,Spring最核心的几个接口
- Spring Boot Mybatis配置项设置
- 提示msvcr71.dll丢失处理办法
- layui 阻止图片上传(before 方法)
- Android 悬浮弹窗window dialog