基本数据类型:8种基本类型、对应的包装类、引用数据类型及与String 之间的转换。

/**
 *   基本数据类型 : 8种基本类型
 *   对应的包装类      引用数据类型     及 与 String 之间的转换。  


 * String   基本数据类型   引用数据类型 之间的转换的联系  。
 * 
 * String.valueOf()   Integer.parseInt();  

 * @author Administrator
 *
 */
public class TestWrapper {
@Test
public  void  StringtoWrapp(){
// 基本数据类型  == 包装类  ===String类 之间的转换。
// 基本数据类型 转换 String  
int i =10;
Integer in =20;
String st= String.valueOf(i);
String st1= String.valueOf(in);

// 字符串转换为  ====基本数据类型 和 引用数据类型 
int sf = Integer.parseInt(st);
System.out.println(sf);
System.out.println(in.toString());
}

@Test
public  void tt(){
int in = 9;
System.out.println(in);

// 基本数据类型 ===》转换引用数据类型 , 直接调用引用类型的构造器 
Integer ins= new Integer(in);
// 包装类 转换为基本数据类型   jdk 5.0 以后废弃  此法, 可以自己拆箱 装箱。
in = ins.intValue();
System.out.println(ins.toString());

Float f= new Float(23.4f);
System.out.println(f.toString());

Boolean  ff =new Boolean("true");
Boolean  f1 =new Boolean(true);

System.out.println(ff+":"+f1);



}
@Test
public void gg(){
// 自动装箱 基本数据类型直接赋值给 包装类
Integer  fg= 13;
// 自动拆箱  -- 包装类 自动转换为 基本数据类型。
int fg1 =fg;

}




}

你可能感兴趣的:(javaSe,java学习实例)