Lesson 22Introduction to Lists
This lesson is a quick introduction to Lists. Lists are a type of data structure that allows you to store values and objects in a more flexible manner than arrays.
LIST
List is an interface that extends Collection. It is an ordered collection of items that may include duplicate elements. The List interface has quite a few methods, but the ones that you will be using most are the following:
add
get
remove
size
We include examples of using these methods in this lesson, but you should read the Javadoc associated with these methods to become familiar with how they work.
TYPES OF LISTS
There are several types of Lists that exist in the Java Collections Framework. Although we will focus on the ArrayList, we will also discuss the LinkedList and Stack so that you are prepared if a situation arises where your program can benefit from them. In addition to the ArrayList, let's take a quick look at the LinkedList and Stack.
ArrayList
Think of the ArrayList class as a supercharged array. Arrays are great data structures, but they have some limitations, especially that once defined, Arrays cannot shrink or grow. An ArrayList can automatically shrink and grow dynamically, so you can easily add or remove ...
Get Job Ready Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.