Java ArrayList trimToSize Example

ArrayList class trimToSize method example. This example shows you how to use trimToSize method.


ArrayList class trimToSize method example.public void trimToSize() Trims the capacity of this ArrayList instance to be the list's current size. An application can use this operation to minimize the storage of an ArrayList instance.

Here is the code

/**
 * @ # TrimToSize.java
 * A class repersenting use to toArray method of ArrayList class in java.util package
 * version 14 May 2008
 * author Rose India 
 */
import java.util.*;

public class TrimToSize {

    public static void main(String args[]) {
        ArrayList arrlist = new ArrayList();
        int i = 0;
        String str = "Rose India";

        //Add the specified element to the end of this list.
        arrlist.add(i);
        arrlist.add(str);
        arrlist.trimToSize();
        System.out.println("Trims the capacity of the arrlist ....");
        System.out.println(arrlist);
        
    }
}

Output
Trims the capacity of the arrlist ....
[0, Rose India]

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US