Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Ibthaj Mansour   on Jun 21 In Java Category.

  
Question Answered By: Geraldine Perkins   on Jun 21

The code:

methodName(String[] args):

means that an array of strings can be passed to this method.

Often you see this:

main(String[] args):

This the args will get passed the command  line argument as an array of
strings. Take this code:


class ProcessFile{
public static void main(String[] args){
System.out.println(args[0]);
}
}

Now if you typed:

java ProcessFile myFile.txt

You will see

myFile.txt

If you did not put  the [] after String, the method main would think it
was getting just one string. But in fact the main method can take many
strings. So the brackets  indicate that the arguement passed to the
method is an array.

Share: 

 

This Question has 5 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Confused about brackets (when used with String command) Or get search suggestion and latest updates.


Tagged: