Is there some methods to determi开发者_如何学JAVAne the number of input arguments from console in Java. Or just compare args[i] to null?
How about using args.length
?
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
.
You could use args.length
to count the arguments.
You could use a library like Apache Commons CLI to parse the arguments.
精彩评论