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