Write one line of code to declare and instantiate an ArrayList of Color objects using the Color class from the lessons. Call the variable palette. |
ArrayList<Color> palette = new ArrayList<Color>(); |
|
Write the code to add Color.RED to an ArrayList of Color objects named palette |
palette.add(Color.RED); |
|
An ArrayList of Colors named palette has been populated with 9 colors. Complete the line of code below to get the last element in the ArrayList. (Use a numeric index.)
Color color = _____________ ; |
palette.get(8) |
|
Complete the code to get the size of an array list named palette.
int size = _______________ ; |
palette.size() |
|
An ArrayList of Color objects named palette has been populated with some unknown number of colors. Complete the line of code below to get the last element in the ArrayList.Color color = _____________ ; |
palette.get(palette.size() - 1) |
|
Complete the code to find the index of the next to the last element in an array list named palette. int index = ____________________________ ;
|
palette.size() - 2 |
|
What will this code segment print?
ArrayList<String> names = new ArrayList<String>();
names.add("Bob");
names.add(0, "Ann");
names.remove(1);
names.add("Cal");
System.out.println(names); |
[Ann, Cal] |
|