Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Array Declaration Bracket Placement

Tags:

java

I'm trying to print "Hello World" from a Java program, but I am a little confused with the main method:

public static void main(String[] args)

and

public static void main(String args[])

Both these functions perform the same task. How does this happen?

I know the function of String but not of the args.

like image 445
webkul Avatar asked Nov 28 '22 05:11

webkul


2 Answers

In Java:

String args[]

is exactly equivalent to:

String[] args
like image 179
cletus Avatar answered Dec 14 '22 03:12

cletus


You are defining a method named "main" which is public (anyone can call it), static (it's a class method, not an instance method), and returns void (does not return anything), and takes a parameter named args that is a String array.

In Java you can declare a String array as:

String[] args

or

 String args[]
like image 45
Jack Leow Avatar answered Dec 14 '22 04:12

Jack Leow