more precise:Note that line.concat("world") does not change line itself. It creates a new String object containing- _ - one space (forum replace 2 white space between world by 1 white space"_hello_world__"
but it is lost because there is no reference to it.
Similarly, calling trim() does not change the object itself.
So the answer is 8 + 5 = 13 !
Note that line.concat("world") does not change line itself. It creates a new String object containing
- _ - one space (forum replace 2 white space between world by 1 white space"_hello__world"
replace but it is lost because there is no reference to it.
Similarly, calling trim() does not change the object itself.
Code: Select all
String blank = " ";// one space
String line = blank + "hello" + blank + blank;
System.out.println("\""+line.concat("world")+"\"");