Java 程序中的字符串字面值都是String类的实例实现
JDK API文档中有这样的介绍:
String 类代表字符串。Java 程序中的所有字符串字面值(如 “abc” )都作为此类的实例实现。
The String class represents character strings. All string literals in
Java programs, such as “abc”, are implemented as instances of this
class.
也就是说,字符串就是个String类对象.
所以创建String类对象不需要new
关键字,只需用双引号即可:
String s = "abc"