This method is sometime very useful for memory management suppose you know value you have assigned to an array list will be final means no more element addition to the array list you can use this to make the memory smaller for that array list
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.
An application can use this operation to minimize the storage of an ArrayList instance.
Example:
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.
An application can use this operation to minimize the storage of an ArrayList instance.
Example:
ArrayList myAL = new ArrayList();
myAL.Add( "Shashwat" );
myAL.Add( "Shriparv" );
So now you know that no more element will be added to myAl, so you can apply:
myAl.trimToSize() to make memory alocation smaller and efficient.
No comments:
Post a Comment
Thank you for Commenting Will reply soon ......