Reputation: 2165
Is there some methods to determine the number of input arguments from console in Java. Or just compare args[i] to null?
Upvotes: 2
Views: 4202
Reputation: 6810
You could use args.length
to count the arguments.
You could use a library like Apache Commons CLI to parse the arguments.
Upvotes: 1
Reputation: 3260
In public static void main(String[] args)
, args
is an array. You can get the number of elements of an (any) array in Java with args.length
. If there are no arguments, the array will have length 0, and args[0]
will give you an ArrayIndexOutOfBoundsException
.
Upvotes: 4