Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1054 :

Posted: Tue Sep 30, 2014 6:19 am
by Smoljanov Sergej
Note that line.concat("world") does not change line itself. It creates a new String object containing
"_hello_world__"
- _ - one space (forum replace 2 white space between world by 1 white space
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 !
more precise:
Note that line.concat("world") does not change line itself. It creates a new String object containing
"_hello__world"
- _ - one space (forum replace 2 white space between world by 1 white space
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")+"\"");

Re: About Question enthuware.ocajp.i.v7.2.1054 :

Posted: Tue Sep 30, 2014 9:08 am
by admin
You are right. Fixed.
thank you for your feedback!