您的位置:首页 > 编程语言 > Java开发

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: