ART MOMENT:
.
![]() |
With student id, museum tickets cost only $8 |
At the end of today's class you should
HAVE READ:
KNOW:
BE ABLE TO:
DAILY QUESTION:
What is wrong with the following code:
/** * Take in an ArrayList of String objects, and output them all to * the screen. */ public void outputAll (ArrayList al) { Iterator it2 = al.iterator(); while (it2.next() != null) { String s = (String) it2.next(); System.out.println (s); } } |
Sample Exam question(s)
1. You are given an ArrayList known to contain String values. Write a method using an Iterator that returns the number of Strings in the ArrayList that are four characters in length.
/** * Take in an ArrayList of String objects and return the number of * Strings that are four characters in length. */ public static int count(ArrayList al) { // Fill in .... } |
2. Convert the following code from a while loop into a for loop
Iterator it = al.iterator(); while (it.hasNext()) { String s = (String) it.next(); System.out.println (s); } |