Java Data StructuresLesson 61Free preview
Java List
This lesson is part of Java · All levels
Summary
List is a Collection interface that stores elements in sequence and allows duplication. Each element has an index starting from zero so it can be accessed and modified directly. The basic operations include add, get, set, remove, and size which are the foundation of almost all list-based programs.
Key points
- The list maintains the order of insertion and allows for twin elements
- Get(i) takes the element, set(i, value) replaces the element in the index
- Add(index, element) inserted in a certain position and moved the element afterwards
- IndexOf(obj) searches for the first position of the element; if no result is −1.
- List.of() makes an immutable list, suitable for constant data
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.