arraylist - Is Java Array list trimToSize() method redundant? -


i think trimtosize() method in java's arraylist unnecessary. understanding is:

let's take array of integers:

int[] = new int[10]; //this allocates ten free slots proactively. 

the major advantage of arraylist can create arrays dynamically @ run time saving memory. code arraylist<integer> arl = new arraylist<integer>(10); not assign ten free slots proactively; instead adds slots when there data stored.

now java specification says trimtosize() remove unused space arraylist, according understanding there won't unused space in arraylist because space created when data available, , when data available unused or free space nil.

your understanding incorrect. if create new arraylist<integer>(10), create array of integer of size 10 filled nulls inside of arraylist nucleus of data model. fill or of slots depending on number of items, , increase size of underlying array if number of items exceeds number of possible size. trimtosize() method has relevance.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -