What does “String[] args” contain in java?

后端 未结 8 1862
终归单人心
终归单人心 2020-12-15 08:18

When I run the following program:

public class Test
{
    public static void main(String[] args)
    {
        System.out.println(args);
    }
{
8条回答
  •  离开以前
    2020-12-15 09:00

    It's a string array.

    1. Modify your code to this:
    public class Test{
       public static void main(String[] args){
           System.out.println(args[0]);
       }
    }
    
    1. Now compile this code:

    $>javac Test.java

    1. Now run:

    $>java Test hello

    This will print: "hello"

    Because "hello" is the argument you are passing to your class.

    If you try: args[x], where x=0..n and run your class via command line: java Test your arguments, then you will see any contents which you pass..

提交回复
热议问题