SJSU/Udacity CS046

Problem Set 6

  1. Array Lists
  2. Vertical Picture List
  3. Shift first to end
  4. Display last picture
  5. Using add
  6. Using set and remove
  7. Get in a Loop
  8. Average char count
  9. Shortest string
  10. Reverse order
  11. Length of strings
  12. Count matches
  13. Find the index
  14. Return match
  15. Four methods
  16. TripPlan
  17. Polygon

Array Lists

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]

Problem on this page?

Your name:

Your email address:

Problem description:

To protect against spam robots, please answer this simple math problem:
× =