"Phil..." <ry***@ieee.org> wrote in message
news:6xxnb.49857$Fm2.24685@attbi_s04...
my book says left to right also
"Glen Herrmannsfeldt" <ga*@ugcs.caltech.edu> wrote in message
(snip)
I thought it would evaluate left to right, so String s = b + a + d + "";
would be equivalent to
String s = ((( b + a ) + d ) + ""; which is not what was asked for. If
you put the "" first it should work, though.
You can also create a StringBuffer, add the chars one at a time, and
then make a String from it.
I did test it with char's before "" and it does add the value instead of
concatenating as strings, as left to right says it should.
My favorite was something like:
System.out.println( 2 + "+" +2+" equals " +2+2);
Personally, I think overloading the + operator was a bad idea. Notice that
Java doesn't allow user operator overloading, as users might apply operators
in confusing ways. Then again, the PL/I string concatenation operator, ||,
was already taken.
The awk concatenation operator, nothing at all, might have worked, though.
-- glen