You are viewing an obsolete version of the DU website which is no longer supported by the Administrators. Visit The New DU.
Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

Reply #5: Somebody's mentioned the first... [View All]

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
This topic is archived.
Home » Discuss » The DU Lounge Donate to DU
aePrime Donating Member (676 posts) Send PM | Profile | Ignore Thu Aug-31-06 09:50 PM
Response to Original message
5. Somebody's mentioned the first...
Edited on Thu Aug-31-06 09:53 PM by aePrime

public class Array
{
public static void main(String[] args)
{
for (int i = 0; i < args.length; ++i) {
System.out.println(args);
}

// Java 5.0
for (String element : args) {
System.out.println(element);
}
}
}


The first will work with any Java version. The second works only in Java 5. The arrays in Java have a length, similar to C++'s STL std::vector (I actually spend all of my time writing C++, but am familiar with Java).

I noticed that the first guy who wrote the loop used "i++". I'm in the habit of writing "++i". Because Java doesn't have operator overloading, it probably doesn't matter, but in C++ "++i" is more efficient than "i++".

(Updated to make the formatting better. DU insists on italiasizing parts of this message.)
Printer Friendly | Permalink |  | Top
 

Home » Discuss » The DU Lounge Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC