Hi
This is a question i found in Khalid Mughal book .
public class q{
public static void main(
String args[]{
String space=""; //1
String composite=space + "hello"+space+space;//2
composite.concat("world");//3
String trimmed=composite.trim();//4
System.out.println(trimmed.length());//5
}
}
options are
5
6
7
12
13
ans is given as 5
but according to me ans shud be 12 .Can anyone plz explain me the reason .
the reason is given in the Khalid Mughal book as strings are immutable but according to me after line 3 composite should point to space hello space space world and the previous string should be available for garbage collection ..
thanks ..