Java基础知识回顾-17(基本类型包装类与System类)

public static void main(String[] args) {
        //将String类型转化为int类型
        String str="12";
        int i=Integer.parseInt(str);
        System.out.println(i--);
        String str2="2.5";
        //将String类型转化为double类型
        double d=Double.parseDouble(str2);
        System.out.println(d);
        
        
    }
	public static void main(String[] args) {
		//基本数据类型+""=String,将int类型转化为String类型。
		int i=9;
		String str=i+"";
		System.out.println(str+1);
		String str1=String.valueOf(i);
		System.out.println(str1+9);
		//调用包装类中的toString(参数)方法
		String str2=Integer.toString(5);
		System.out.println(str2+5);
	}
public class Demo03 {
	public static void main(String[]args){
		method3();
	}
	public static void method(){
		//运用调用包装类中的valueof方法给对象赋值
		Integer in1=new Integer(3);
		Integer in2=new Integer("123");
		Integer in3=Integer.valueOf(5);
		Integer in4=Integer.valueOf("5");
		//integer转为int
		int i=in1.intValue();
		System.out.println(i);
		System.out.println(in3);
	}
	public static void method2(){
		//自动装箱和自动拆箱
		Integer i= 5;
		Integer k=6;
		System.out.println(i+k);
	}
	public static void method3(){
		Integer in=200;
		Integer in2=200;
		System.out.println(in==in2);
		System.out.println(in.equals(in2));
	}
	//在自动拆装箱中,如果你是byte数值以内,先创建一个对象,那么后来的都指向第一个对象的地址。
}

 System常用方法:

  System类不能手动创建对象,因为构造方法被private修饰,阻止外界创建对象。System类中的都是static方法,类名访问即可。在JDK中,有许多这样的类。

猜你喜欢

转载自www.cnblogs.com/zhangrui0328/p/9092384.html