在java中字符串的實(shí)例化有兩種方式,分別是:
1、直接賦值
String str = "Hello World";
2、構(gòu)造方法實(shí)例化
String str = new String("Hello World");
(視頻教程推薦:java視頻)
具體實(shí)例:
//直接賦值 public class StringDemo{ public static void main(String[] args) { String str1 = "Hello qty"; String str2 = "Hello qty"; } } //構(gòu)造方法實(shí)例化 public class StringDemo{ public static void main(String[] args) { String str1 = new String("Hello qty"); } }
推薦教程:java入門(mén)程序