Thursday, April 26, 2012

trimToSize or trimTolength

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: 

     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 ......

Featured Posts

How to add "Copy to" and "Move to" options to the right-click context menu in Windows:

Method 1: Registry Editor (Manual) Note: Back up your registry first or create a system restore point. Add "Copy to" Option:...