package 包装类;
import org.junit.Test;
public class TestWrapper {
@Test
public void test1(){
int i =
10;
float f =
10.1f;
Integer i1 =
new Integer(i);
Float f1 =
new Float(f);
String str =
"123";
Float f2 =
new Float(
1.0);
Float f3 =
new Float(
"1.0");
System.
out.println(
"基本数据类型转成包装类:"+f2);
System.
out.println(
"基本数据类型转成包装类:"+f3);
String str1 = String.valueOf(f);
String str2 = f+
" ";
System.
out.println(
"基本数据类型转换成String:"+str1);
System.
out.println(
"基本数据类型转换成String:"+str2);
int i2 = i1.intValue();
int i3 = i1;
System.
out.println(
"包装类转换成基本数据类型"+i2);
System.
out.println(
"包装类转换成基本数据类型"+i3);
String str3 = f1.toString();
String str4 = Float.toString(f1);
System.
out.println(
"包装类转换成String类"+str3);
System.
out.println(
"包装类转换成String类"+str4);
int i4 = Integer.parseInt(str);
int i5 = Integer.valueOf(str);
System.
out.println(
"String类转换成基本数据类型"+i4);
System.
out.println(
"String类转换成基本数据类型"+i5);
Integer i6 =
new Integer(str);
System.
out.println(
"String类转换成包装类"+i6);
}
}