-
Book Overview & Buying
-
Table Of Contents
OCA: Oracle Certified Associate Java SE 8 Programmer I Study Guide: Exam 1Z0-808
By :
An array has one glaring shortcoming: you have to know how many elements will be in the array when you create it and then you are stuck with that choice. Just like a StringBuilder, ArrayList can change size at runtime as needed. Like an array, an ArrayList is an ordered sequence that allows duplicates.
As when we used Arrays.sort, ArrayList requires an import. To use it, you must have either of the following two statements in your class:
import java.util.*; // import whole package including ArrayList
import java.util.ArrayList; // import just ArrayList
Remember that if you are shown a code snippet with a line number that doesn't begin with 1, you can assume the necessary imports are there. Similarly, you can assume the imports are present if you are shown a snippet of a method.
In this section, we'll look at creating an ArrayList, common methods, autoboxing, conversion, and sorting.
Experienced programmers, take note: This section is simplified...
Change the font size
Change margin width
Change background colour