Java Data StructuresLesson 62Free preview
Java ArrayList
This lesson is part of Java · All levels
Summary
ArrayList is a List implementation that is stored as a dynamic array and automatically enlarges when capacity runs out. Access using indexes such as get and set is very fast, while insertion or deletion in the middle is slower because the elements have to be moved. This structure is most often used for data that is more read than modified.
Key points
- It can grow dynamically; new ArrayList<>(starting capacity) saves redistribution
- The get/set index-based operation runs O(1), while the add-center and remove-center O(n)
- The main method: add, remove(index), remove(obj), set, get, contains, size
- Allowing the null element and maintaining duplicates
- Not thread-safe; for multithreaded environments use Collections.synchronizedList()
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.