WebHosting

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

Error Message in DBeaver connecting using jdbc: Public Key Retrieval is not allowed

Fixing “Public Key Retrieval is not allowed” Error in MySQL with DBeaver   If you are trying to connect MySQL 8+ with DBeaver and suddenly...