Errr... that's because you didn't capture the return value. Try: String str2 = str.toLowerCase();
"I'm not back." - Bill Harding, Twister
Joined: Aug 09, 2002
Hi, Perhaps I'm not that clear in my 1st posting but actually what I want to know is whether there is any specific reasons as to why Java allow that to happen. s1.toLowerCase(); The statement above doesn't really has any effect unless we store the return value in a variable or print it out. And btw, where the return value goes for the statement above (aren't we expecting a value from that)?
Sometimes you *want* to ignore the return value. For example, StringBuffer.append is returning the StringBuffer itself, so that you can write statements like: strBuff.append(x).append(y).append(z); If the compiler would force you to somehow use the return value, you had to write strBuff = strBuff.append(x).append(y).append(z);
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Jan 30, 2000
From the compiler's point of view, it can't tell the difference between methods like String's toUpperCase() and StringBuffer's append(). It would take a very sophisticated compiler to identify those methods which had no other side effects and which therefore should only be used by capturing a return value.