Skip to main content\(\newcommand{\N}{\mathbb N} \newcommand{\Z}{\mathbb Z} \newcommand{\Q}{\mathbb Q} \newcommand{\R}{\mathbb R}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 7.2 Starter Level
ArrayLists
Objectives
Instantiate an ArrayList
Use add()
, get()
, set()
, remove()
, and size()
Iterate through an ArrayList
using a for loop
Subsection 7.2.1 Instructions
Initialize an ArrayList
and add the following elements: "Butter", "Milk", "Cookies", "Chips", "Carrots"
Remove the third item from the list
Replace the second item in the list with "Pancakes"
Remove the last item from the list
Add "Apples" to the list
Print the size of the list
Print the contents of the list using a for loop
The expected output is:
Size of the list: 3
Contents of the list:
Butter
Milk
Chips
Apples
You have attempted
of
activities on this page.