StringBuffer sb = new StringBuffer("abc");
StringBuffer sb1 = sb;
StringBuffer sb2 = new StringBuffer("abc");
How many objects are created?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
StringBufferobjects are created because there is 2new.Stringobject is created [JLS, 3.10.5 => It is guaranted that the object will be reused by any other code running in the same virtual machine that happens to contain the same string literal]