
Hi,
Here is my code
public static void main(String[] args) {
String s1 = "abc"; StringBuffer s2 = new StringBuffer(s1); StringBuffer s3
= s2; StringBuffer s4 = new StringBuffer(s1);
}
in this example how many objects are created ?
could you please explain.

The only difference between StringBuffer and StringBuilder is that StringBuilder is unsynchronized whereas StringBuffer is synchronized. So when the application needs to be run only in a single thread then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer.
For more information, visit the following link:
http://www.roseindia.net/java/java-tips/data/strings/23stringbufferetc.shtml
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.