String[in Java] args

Source: Internet
Author: User

In each Java program there is a method, public static void main (string[] args) method, this parameter for a long time did not understand, but carefully, it is quite simple, all the parameters of the method is a truth, And this main method is different: It is the first one to run in all methods, so there is no other way to pass parameters, so you need to rely on the runtime command line input parameters, so string args, received command line input,

Package test_main;

public class Test_main {
public static void Main (string[] args) {
System.out.println ("Args[0" is "+ args[0]);
System.out.println ("Args[1" is "+ args[1]);
System.out.println ("args[2] is");
}
}

Write a test program, run on Eclipse, the past is a click to run on the line, today tried a few times, and then put the command line to run (cmd that), compile: Javac Test.java run: Java Test Hello World display:

Args[0] is Hello
ARGS[1] is world
ARGS[2] is

Is can run, thought: Eclipse so strong This certainly can do, later on-line a check, in fact very simple, is to open the Debug configuration inside the run, inside the arguments input you want to input parameters, and then save, come out click the Run button, Ok



The results come out and show the parameters just entered

Args[0] is Hello
ARGS[1] is world
ARGS[2] is

String[in Java] args

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.