Content deleted Content added
mNo edit summary |
m formatting |
||
Line 5:
==For each==
List<String> curses = new ArrayList<String>();<BR>
curses.add("foo");
curses.add("bar");
curses.add("snafu");<BR>
// The old iterator...
String result = "";<BR>
for (Iterator it = curses.iterator(); it.hasNext(); ) {
result += (String)it.next();
}<BR>
assert result.equals("foobarsnafu");<BR>▼
// The new Java 1.5 iterator...<BR>▼
▲ assert result.equals("foobarsnafu");
▲ // The new Java 1.5 iterator...
result = "";
for (String s: curses) { result += s; } // fits neatly on one line!<BR>
assert result.equals("foobarsnafu");
|