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

Warp AI Terminal 🔥 | The Future of Coding? Agentic Dev Environment Explained!

  Warp AI Terminal 🔥 | The Future of Coding? Agentic Dev Environment Explained! What if your terminal could think, assist, and even act li...