public static void main(String args)
This array is the mechanism through which the runtime system passes information to your application. Each String in the array is called a command-line argument. Command-line arguments let users affect the operation of the application without recompiling it. For example, a sorting program might allow the user to specify that the data be sorted in descending order with this command-line argument:
getting curious about it, i wrote this:
i wsnt expecting this:
C:\javas>java TesteOrdenar -descending
How, in the end, does it works?
For example, a sorting program might allow the user to specify that the data be sorted in descending order with this command-line argument:
...if you write a sorting program that takes a command-line argument and knows what to do with it. This is simply a suggestion of how you might decide to implement a command-line argument.
In your code, the String "-descending" is simply being assigned to args, but never used. The elements of the ArrayList are being printed in the order they were added. See what happens when you enter "j", "a", "v", "a" as elements.
Originally posted by miguel lisboa:
never mind: i was thiking of it as a sort of reserved or keyword, like when we type java -version at command line
Note that these hyphenated options are immediately after the "java" command before any file name; whereas arguments are after a file name. You can see a list of options by simply typing java and pressing enter.