This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hi What is the result of the following code: StringBuffer sb1="ab"; StringBuffer sb2=new StringBuffer("ab"); 1.sb1==sb2 2.sb1.equals(sb2) I think both are false.If I am wrong please correct me.Thanks
I think that both are false too. 1) == returns true if both are initialize with literals and both are identical literal strings. 2) The equals method isn�t implemented in StringBuffer
[This message has been edited by Marcela Blei (edited July 21, 2000).]
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Are you sure about StringBuffer sb1="ab"; I guess it will not compile. The error will be incompatible type case. Yes StringBuffer did not override the equals() method and so it will not compare the contents. It will behave just like ==. Hope it helps!