What is the result of the following code?
3: String s = "ABCD"; 4: s.toUpperCase(); 5: s.trim(); 6: s.substring(1, 3); 7: s += " two"; 8: System.out.println(s.length());
C.
String objects are immutable.
Line 4 5 6 have no impact on the s value.
public class Main{ public static void main(String[] argv){ String s = "ABCD"; s.toUpperCase(); /*from w ww .j av a2s.c o m*/ s.trim(); s.substring(1, 3); s += " two"; System.out.println(s.length()); } }