3:11 pm - Sunday November 23, 6436

To Check String Capacity using String Capacity Method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

                                  In this Tutorial you will learn how to Check String capacity Using StringBuffer Capacity Method With Example program.

public class StringBufferCapacityExample {
	public static void main(String args[]) {
		StringBuffer sb = new StringBuffer();
		System.out.println(sb.capacity());
		sb.append("Student");
		System.out.println(sb.capacity());
		sb.append("Student Mark List");
		System.out.println(sb.capacity());
	}
}

Output

16

16

34

Explanation:

public int capacity()

Returns the current capacity. The capacity is the amount of storage available for newly inserted characters, beyond which an allocation will occur.

Returns:

the current capacity

 

BACK

Filed in: Java Examples

Comments are closed.