Disadvantages of using ArrayList

ArrayList class implements List interface and it is based on an Array data structure. It is widely used because of the functionality and flexibility it offers.

Time Complexity — If a new data is added or removed from an ArrayList data in entire list has to be shifted to update it which will result into a time complexity of o(n).

ArrayList have a sequential memory representation , so larger the list more complex it is to get allocated in the memory

ArrayList is loosely typed so boxing and unboxing takes place which hits its performance.

ArrayLists cannot hold primitive data types such as int, double, char, and long (they can hold String since String is an object, and wrapper class objects (Double, Integer).

ArrayList is unsynchronised, making them, therefore, not thread safe. With that difference in mind, using synchronisation will incur a performance hit. So if you don’t need a thread-safe collection, use the ArrayList . If you want to make it thread safe ,

Collections.synchronizedList(new ArrayList<YourClassNameHere>())

List is a super type of ArrayList so you need to specify that.

Most of the developers choose ArrayList over Array as it’s a very good alternative of traditional java arrays. But above are some use cases where you should say NO to ArrayList.

A universe of atoms , an atom in the universe. ⚛️