Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Buffer

 
adbob adbob
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi any can help me to know how it is printing only
'ABCDEFG' for the below question.
class M{
public static void main (String[] args) {
StringBuffer s1 = new StringBuffer();
s1.ensureCapacity(16);
s1.append("ABCDEFG");
s1.setLength(35);
System.out.print(s1 + "," + s1.capacity());
}
}
Thanks in Advance
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My old Zen Master asked me once:
"What is the appearence of a null character printing?"
Thankyou for giving me one more opportunity to read the API for StringBuffer.
-Barry
[ January 02, 2003: Message edited by: Barry Gaunt ]
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I run the program, the output is:

Rene
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic