首页 > 应用开发 > Java > Java 面向对象 之 基本数据 包装类
转载于 : http://www.verejava.com/?id=16992869307361
/**
知识点: 基本数据类型 对应的 包装类
1. 基本数据类型包括:
1. 数值类型
1.1 byte -> Byte
1.2 short -> Short
1.3 int -> Integer
1.4 long -> Long
1.5 float -> Float
1.6 double -> Double
2. 字符型
2.1 char -> Character
3. 布尔型
3.1 boolean -> Boolean
2. 包装类的应用
2.1 使基本数据类型也可以有引用类型
2.2 实现数据类型的转换功能
注意:
1. 在jdk 1.5 之后 基本数据类型和包装类型是可以相互赋值
*/public class WrapClass {
public static void main(String[] args)
{
Byte a=1; byte b=10;
a=b;
System.out.println(a.byteValue());
System.out.println(Integer.valueOf(b)); //包装类的应用 主要是 数据类型的转换
//整型转 double 型
int c=100;
Integer d=new Integer(c);
System.out.println(d.doubleValue()); //整型转 long 型
System.out.println(d.longValue()); //整型转 字符串
String str=Integer.toString(d);
System.out.println(str); //字符串转 整型
int e=Integer.parseInt(str);
System.out.println(e);
System.out.println(Integer.toBinaryString(e));
System.out.println(Integer.signum(e));
System.out.println(Integer.bitCount(e));
System.out.println(Integer.highestOneBit(e));
System.out.println(Integer.numberOfLeadingZeros(e));
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10054744/viewspace-2213856/ ,如需转载,请注明出处,否则将追究法律责任。