Java包装类

来源:互联网 发布:网络拓扑图绘制 编辑:程序博客网 时间:2024/06/07 01:36

各类型包装类的使用方法:

/** * 测试包装类 * @author 30869 * */public class TestWrapperClass {public static void main(String[] args) {//Boolean(boolean value)         //分配一个表示 value 参数的 Boolean 对象。         //Boolean(String s)         //如果 String 参数不为 null 且在忽略大小写时等于 "true",则分配一个表示 true 值的 Boolean 对象。 //Boolean b1=new Boolean(true);//Boolean b2=new Boolean(false);//Boolean b3=new Boolean("true");//Boolean b4=new Boolean("false");//Boolean b5=new Boolean("TRUE");//Boolean b6=new Boolean("FALSE");//Boolean b7=new Boolean("fals");//System.out.println(b1);//System.out.println(b2);//System.out.println(b3);//System.out.println(b4);//System.out.println(b5);//System.out.println(b6);//System.out.println(b7);/* * Byte(byte value)                       构造一个新分配的 Byte 对象,以表示指定的 byte 值。            Byte(String s)                      构造一个新分配的 Byte 对象,以表示 String 参数所指示的 byte 值。          *///Byte byte1=new Byte("127");//System.out.println(byte1);///* * Character(char value)                       构造一个新分配的 Character 对象,用以表示指定的 char 值。 * *///Character character=new Character('8');//System.out.println(character);/*Double(double value)                     构造一个新分配的 Double 对象,它表示基本的 double 参数。   Double(String s)                    构造一个新分配的 Double 对象,表示用字符串表示的 double 类型的浮点值。 *///Double double1=new Double("456");//Double double2=new Double(456);//System.out.println(double1);//System.out.println(double2);/*Float(double value)           构造一个新分配的 Float 对象,它表示转换为 float 类型的参数。 Float(float value)           构造一个新分配的 Float 对象,它表示基本的 float 参数。 Float(String s)           构造一个新分配的 Float 对象,它表示用字符串表示的 float 类型的浮点值。 *///Float float1=new Float("52.6");//double d=78.56;//Float float2=new Float(d);//Float float3=new Float(52.6);//System.out.println(float1);//System.out.println(float2);//System.out.println(float3);/*Integer(int value)           构造一个新分配的 Integer 对象,它表示指定的 int 值。 Integer(String s)           构造一个新分配的 Integer 对象,它表示 String 参数所指示的 int 值。 */////Integer integer=new Integer("789");//Integer integer2=new Integer(789);//System.out.println(integer);//System.out.println(integer2);////包装类转换基本数据类型/* *  Double(double value)                       构造一个新分配的 Double 对象,它表示基本的 double 参数。            Double(String s)                      构造一个新分配的 Double 对象,表示用字符串表示的 double 类型的浮点值。  * *///Integer integer=new Integer("123");//int i=integer.intValue();//System.out.println(i);//Double double1=new Double(89.3);//double d=double1.doubleValue();//System.out.println(d);//Boolean boolean1=new Boolean("TRUE");//boolean b=boolean1.booleanValue();//System.out.println(b);//Character character2=new Character('j');//char c=character2.charValue();//System.out.println(c);}}


原创粉丝点击