Sunday, 6 July 2014

ensureCapacity (int minimumCapacity)

public synchronized void ensureCapacity(int minimumCapacity)
Ensures that the capacity is at least equal to the specified minimum. If the current capacity is less than the argument, then a new internal array is allocated with greater capacity. The new capacity is the larger of:
   1. The minimumCapacity argument.
   2. Twice the old capacity, plus 2. 


public class StringBufferEnsureCapacity {
     public static void main(String args[]){
        StringBuffer str1 = new StringBuffer("Hi How are you");
        
        System.out.println("str1 capacity is");
        System.out.println(str1.capacity());
        
        System.out.println("str1 capacity is");
        str1.ensureCapacity(50);
        System.out.println(str1.capacity());
    }       
}

Output
str1 capacity is
30
str1 capacity is
62





Prevoius                                                 Next                                                 Home

No comments:

Post a Comment