| Author |
String predefined method doubt???
|
Vishal Hegde
Ranch Hand
Joined: Aug 01, 2009
Posts: 970
|
|
public class SB
{
public static void main(String args[])
{
StringBuffer s1=new StringBuffer();
StringBuffer s2=new StringBuffer();
s1.insert(0,"Hello from Java");
s2.insert(0, s2);
System.out.println(s1);
System.out.println(s2);
}
}
s2 is displaying nothing not even null as it is not even referecing to any object ,why is this happening???
|
http://www.lifesbizzare.blogspot.com || OCJP:81%
|
 |
salvin francis
Ranch Hand
Joined: Jan 12, 2009
Posts: 915
|
|
Answer seems to be posted here:
http://www.coderanch.com/t/473341/Java-General/java/with-string-predefined-method
Please note OP in both the cases
|
My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
This problem is slightly different.
Vishal, what does s2 contain when you try to add it to itself? Also, please use code tags in the future.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32611
|
|
And also, your thread title doesn't quite tell us what the question is about. StringBuffer, not String, please.
By the way: StringBuilder is usually more efficient in that sort of circumstances.
|
 |
 |
|
|
subject: String predefined method doubt???
|
|
|