What is the setLength() method?

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

What is the setLength() method?

Rating:

The setLength() method of the StringBuffer class sets the length of the buffer within the StringBuffer object. Its general form is as follows:

void setLength(int len)

Here, len specifies the length of the new buffer. Its value should be always non-negative. If the size is set to a value greater than the length of the existing buffer, sufficient null characters will be added to the existing buffer, or if the size is set to a value, which is less than the length of the existing buffer, all characters (including spaces) stored beyond the specified length, will be lost.

For example:

StringBuffer s=new StringBuffer("have a nice day");
s.setLength(5);


Here, the size of the existing buffer is 15, but it is set to 5. Therefore, all characters (including spaces), which are beyond this limit, will be lost. The new string will be "have".


Rating:



Other articles

Click here to Article home

 
uCertify.com | Our Company | Articles | Privacy | Security | Contact Us | News and Press Release | uCertify India
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.