Java 1.5: Difference between revisions

Content deleted Content added
mNo edit summary
Cewbot (talk | contribs)
Tag: Redirect target changed
 
(9 intermediate revisions by 8 users not shown)
Line 1:
#REDIRECT [[Java version history#Java SE 5]]
'''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.
 
{{Redirect category shell|1=
This version of Java contains long-awaited syntax shortcuts such as [[foreach]], [[autoboxing]] and [[typesafe enum]]s. To turn on these features, you must provide the "-source 1.5" switch to the compiler.
{{R to section}}
 
}}
==For each==
 
This code snippet shows the old and new [[for loop]] syntax.
 
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>
result = "";
for (String s: curses) { result += s; } // fits neatly on one line!<BR>
assert result.equals("foobarsnafu");
 
==Autoboxing==
 
 
==Links==
*[http://java.sun.com/features/2003/05/bloch_qa.html New Language Features for Ease of Development in the Java 2 Platform, Standard Edition 1.5: A Conversation with Joshua Bloch]