JAVA

    科技2026-04-08  9

    单元测试

    包装类

    我们希望JAVA中的基本数据类型的变量也具有类的特征

    基本数据类型包装类byteByteshortShortintIntegerlongLongfloatFloatdoubleDoublecharCharacterbooleanBoolean

    基本数据类型,String,包装类之间如何相互转化

    基本数据类型 转 包装类 ,

    int num1=10; Integer in1=new Integer(num1);

    包装类 转 基本数据类型 ,

    Integer in1=new Integer(12); int i1=in1.intValue();

    JDK 5.0新特性自动装箱 //自动装箱,基本数据类型转化为包装类 int num2=10; Integer in2=num2; boolean b1=false; Boolean b2=b1;

    基本数据类型和包装类转String int num1=10; 方式1: String str1=num1+""; 方式2: String str2=String.valueOf(num1);

    String转基本数据类型 int num2=Integer.parseInt(str1);

    Processed: 0.013, SQL: 11