The first code is shown below:
String s = "hello";
The second code is shown below:
String s = new String("hello");
Question: Are the two codes invoking the same constructor of String(char[])
?
String
has a private final field char value[]
. Why is it set to a final
field? Such we will create a new String
every time we invoke change the value of string. What is the purpose to set the field char value[]
to final
?