Java 1.5
Appearance
Java 1.5(the "Tiger" relase) became available in Beta in February 2004. Like all versions of Java, it can be downloaded at no charge from Sun's website.
This version of Java contains long-awaited syntax shortcuts such as foreach, autoboxing and typesafe enums. To turn on these features, you must provide the "-source 1.5" switch to the compiler.
For each
This code snippet shows the old and new for loop syntax.
List<String> curses = new ArrayList<String>();
curses.add("foo"); curses.add("bar"); curses.add("snafu");
// The old iterator... String result = "";
for (Iterator it = curses.iterator(); it.hasNext(); ) { result += (String)it.next(); }
assert result.equals("foobarsnafu");
// The new Java 1.5 iterator...
result = ""; for (String s: curses) { result += s; } // fits neatly on one line!
assert result.equals("foobarsnafu");