Granny's Programming Pearls The moose likes Programmer
Certification (SCJP/OCPJP) and the fly likes + Operator in
String Big Moose Saloon Register / Login  Bookmark "+ Operator
in String" Watch "+ Operator in String" New topic  + Operator in
String  Poornima Sharma Ranch Hand  Joined: Sep 09, 2008 Posts:
114 Why does + operator in string does not create a new String?
Poornima Sharma SCJP 6.0 Henry Wong  Joined: Sep 28, 2004 Posts:
17960  Where have you heard that it does not? Or are you asking
why *does* it create a new string?   victor kamat Ranch Hand
Joined: Jan 10, 2007 Posts: 247 When you do  String str = "abc";
str = str + "be";  then the JVM creates string "abc" and then
when you do the second operation, it creates a second string
"abcbe" and assigns to the reference str.  If now you do String
x = "abcbe" then x refers to the same object that str refers
above ( after the 2nd assignment).  But if you do String x = new
String("abcbe"); then x refers to another object altogether.
chander shivdasani Ranc