Java记录 -30- 包装类
2015-09-13 18:45
477 查看
包装类(Wrapper Class),针对于原生数据类型的包装。
1. Java提供了8种原生数据类型。但在使用过程中,许多地方都需要使用对象类型,而原生数据类型不是对象,这时就需要将原生数据类型包装成对象类型来使用。
2. Java为8种原生数据类型都提供了包装类。包装类的对象中承载了具体的原生数据类型的值。
3. 我们可以像用对象类型的操作来操作原生数据类型。所有的包装类(8种)都位于java.lang包下。
4. Java 中八个包装类分别是:Byte、Short、Integer、Long、Float、Double、Character、Boolean。他们的使用方式都是一样的,可以实现原生数据类型和包装类型的双向转换。
使用实例:
public static void main(String[] args){
int i = 3;
Integer integer = new Integer(i);
int ii = integer.intValue();
System.out.println(i == ii);
}
Class Integer
java.lang.Object
java.lang.Numberjava.lang.IntegerAll Implemented Interfaces:
Serializable, Comparable<Integer>
public final class Integer extends Number implements Comparable<Integer>
The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.
In addition, this class provides several methods for converting an int to a String and a String to an int, as well as other constants and methods useful when dealing with an int.
1. Java提供了8种原生数据类型。但在使用过程中,许多地方都需要使用对象类型,而原生数据类型不是对象,这时就需要将原生数据类型包装成对象类型来使用。
2. Java为8种原生数据类型都提供了包装类。包装类的对象中承载了具体的原生数据类型的值。
3. 我们可以像用对象类型的操作来操作原生数据类型。所有的包装类(8种)都位于java.lang包下。
4. Java 中八个包装类分别是:Byte、Short、Integer、Long、Float、Double、Character、Boolean。他们的使用方式都是一样的,可以实现原生数据类型和包装类型的双向转换。
使用实例:
public static void main(String[] args){
int i = 3;
Integer integer = new Integer(i);
int ii = integer.intValue();
System.out.println(i == ii);
}
Class Integer
java.lang.Object
java.lang.Numberjava.lang.IntegerAll Implemented Interfaces:
Serializable, Comparable<Integer>
public final class Integer extends Number implements Comparable<Integer>
The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.
In addition, this class provides several methods for converting an int to a String and a String to an int, as well as other constants and methods useful when dealing with an int.
相关文章推荐
- Java线程池使用说明
- java集合框架之java HashMap代码解析
- Java中HashMap实现原理初探
- Java学习笔记——cmd对java的编译以及cmd对cpp的编译
- java多线程
- Java并发编程:线程池的使用
- 解决在windows的eclipse上面运行WordCount程序出现的一系列问题详解
- java编程---万年历
- java String分类trim,substring,replaceAll,indexOf使用功能
- java中接口有什么作用?请创建一个接口(举例)
- java程序性能优化第三章
- java__泛型
- Spring MVC @ResponseBody 提示 406 The resource identified by this request……
- Java记录 -28- String Literals字面值
- apktool + eclipse 调试smali
- java-使用SImpleDateFormat格式化时间输出
- Java记录 -27- String的intern方法
- springMVC是线程安全的吗?
- spring mvc jsp页面无法解析
- java中vector与arraylist的区别