Jump to content

Java 1.5

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ed Poor (talk | contribs) at 15:17, 27 April 2004 (=For each= source code example). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Java 1.5 is scheduled for release in 2004; as of April 2004, the beta version is available. Like all versions of Java, it can be downloaded at no charge from Sun's website.

This version of Java, codenamed "Tiger", contains long-awaited syntax shortcuts such as foreach and autoboxing.

For each

The new for loop syntax is illustrated in the following source code snippet:

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");

Autoboxing