Simple Basic Java Software – analysing arguments from command line

[problem]

You want a simple bit of java code that takes arguments from the command line and displays them.

[/problem]

[solution]

Good demo on how to obtain and handle java arguments.

  public class Arguments {    public static void main(String argv[]) {      if(argv.length > 0) {        System.out.println("args exec w " + argv.length + " args");          for(int i=0;i... 

[/solution]

[example]

Here is a demo:

 # java Arguments -a -x -y args exec w 3 args argv[0] = -a argv[1] = -x argv[2] = -y 

[/example]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *