-2

I know String in Java is immutable. Consider:

String s = "Java";
s = s.concat(" is simple");
System.out.println(s); //prints Java is simple

Here the value of String s is changed? Can someone explain me, how String concat actually works?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

0

s.concat(" is simple") returns a new string and s = s.concat(" is simple") assigns this new string to variable s.

reformed
  • 4,505
  • 11
  • 62
  • 88