A Java String
contains an immutable sequence of Unicode characters. Unlike C/C++, where string is simply an array of char
, A Java String
is an object of the class java.lang
.
Java String
is, however, special. Unlike an ordinary class:
String
is associated with string literal in the form of double-quoted texts such as "Hello, world!". You can assign a string literal directly into aString
variable, instead of calling the constructor to create aString
instance.- The
'+'
operator is overloaded to concatenate twoString
operands.'+'
does not work on any other objects such asPoint
andCircle
. String
is immutable. That is, its content cannot be modified once it is created. For example, the methodtoUpperCase()
constructs and returns a newString
instead of modifying the its existing content.