第四章01 String类对象的两种实例化方式

String类的两种实例化方式:

    直接赋值:String 对象 = "内容";
    构造方法:public String(String s);

范例1:直接赋值

public class StringDemo{
	public static void main(String args[]){
		String str = "hello ";
		str = str + "world!";
		System.out.println(str);
	}
}

范例2:构造方法

public class StringDemo{
	public static void main(String args[]){
		String str = new String("hello ");
		str = str + "world!";
		System.out.println(str);
	}
}

猜你喜欢

转载自blog.csdn.net/guxunshe5199/article/details/81126500