- Home /
Arraylist vs List,Arraylist vs list
I know that Arraylist is pretty much the same as List, both can store whatever objects I want. So is there any situation that I need to use List over arraylist or vice versa?,
Answer by cronywalls · Feb 05, 2019 at 06:47 AM
ArrayList provides some thread-safety through the Synchronized property, which returns a thread-safe wrapper around the collection. The wrapper works by locking the entire collection on every add or remove operation. Therefore, each thread that is attempting to access the collection must wait for its turn to take the one lock. This is not scalable and can cause significant performance degradation for large collections.
List does not provide any thread synchronization; user code must provide all synchronization when items are added or removed on multiple threads concurrently.
Using ArrayList in 64bit operating system takes 2x memory than using in the 32bit operating system. Meanwhile, generic list List will use much low memory than the ArrayList.