包装类和类相互转换

1:      //int<-->Integer

        int a=7;

Integer a1 =new Integer(a);

int a2=a1.intValue();

System.out.println(a1);

System.out.println(a2);

//byte<-->Byte

byte b=23;

Byte b1=new Byte(b);

byte b2=b1.byteValue();

System.out.println(b1);

System.out.println(b2);

//boolean<-->Boolean

boolean c=true;

Boolean c1=new Boolean(c);

boolean c2=c1.booleanValue();

System.out.println(c1);

System.out.println(c2);

//char<-->Character

char d=2;

Character d1=new Character(d);

char d2=d1.charValue();

System.out.println(d1);

System.out.println(d2);

//short<-->Short

short e=55;

Short e1=new Short(e);

short e2=e1.shortValue();

System.out.println(e1);

System.out.println(e2);

//long<-->Long

long f=68;

Long f1=new Long(f);

long f2=f1.longValue();

System.out.println(f1);

System.out.println(f2);

//float<-->Float

float g=24;

Float g1=new Float(g);

float g2=g1.floatValue();

System.out.println(g1);

System.out.println(g2);

//double<-->Double

double h=5.4;

Double h1=new Double(h);

double h2=h1.doubleValue();

System.out.println(h1);

System.out.println(h2);

2: //String-->byte

String str="111";

byte a1=Byte.parseByte(str);

System.out.println(a1);

//byte-->String

byte a2=2;

String a3=a2+"";

String a4=String.valueOf(a2);

//String-->Byte

String str1="222";

Byte b=new Byte(str1);

Byte b1= Byte.valueOf(str1);

//Byte-->String

Byte c=new Byte((byte) 333);

String c1=c+"";

String c2=String.valueOf(c);

//String-->boolean

String str2="333";

boolean d=Boolean.parseBoolean(str2);

System.out.println(d);

//boolean-->String

boolean d1=true;

String d2=d1+"";

String d3=String.valueOf(d1);

//String-->Boolean

String str3="222";

Boolean d4=new Boolean(str3);

Boolean d5= Boolean.valueOf(str3);

//Boolean-->String

Boolean d6=new Boolean(str3);

String d7=d6+"";

String d8=String.valueOf(d6);

//String-->char

     char e='就';

     char e1 = Character.valueOf(e);

     System.out.println(e1);

//char-->String

char e2=5;

String e3=e2+"";

String e4=String.valueOf(e2);

//String-->Character

char str4='你';

Character e5=new Character(str4);

Character e6=Character.valueOf(str4);

//Boolean-->String

Boolean e7=new Boolean(str3);

String e8=e7+"";

String e9=String.valueOf(e7);

   //String-->short

     String str5="888";

     short f1=Short.parseShort(str5);

     System.out.println(f1);

   //short--->String

     short f2=888;

     String f3=f2+"";

     String f4=String.valueOf(f2);

    //String-->Short

     String str6="555";

     Short f5= new Short(str6);

     Short f6=Short.valueOf(str6);

    //Short-->String

     Short f7=new Short(str6);

     String f8=f7+"";

     String f9=String.valueOf(f7);

     

     //String-->long

     String g="744";

     long g1=Long.parseLong(g);

     System.out.println(g1);

   //long--->String

     long g2=124;

     String g3=g2+"";

     String n4=String.valueOf(g3);

    //String-->Long

     String str7="236";

     Long g5= new Long(str7);

     Long g6= Long.valueOf(str7);

    //Long-->String

     Long g7=new Long(str7);

     String g8=g7+"";

     String g9=String.valueOf(g7);

     

     //String-->float

     String h="193";

     float h1=Float.parseFloat(h);

     System.out.println(h1);

   //float--->String

     float h2=193;

     String h3=h2+"";

     String h4=String.valueOf(h3);

    //String-->Float

     String str8="193";

     Float h5= new Float(str8);

     Float h6= Float.valueOf(str8);

    //Float-->String

     float h7=new Float(str8);

     String h8=h7+"";

     String h9=String.valueOf(h7);

     

     //String-->double

     String i="452";

     double i1=Double.parseDouble(i);

     System.out.println(i1);

   //double--->String

     double i2=999;

     String i3=i2+"";

     String i4=String.valueOf(i3);

    //String-->Double

     String str9="452";

     Double i5= new Double(str9);

     Double i6=Double.valueOf(str9);

    //Double-->String

     Double i7=new Double(str9);

     String i8=i7+"";

     String i9=String.valueOf(i7);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值