开发者

How to determine the number of the input arguments in Java

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜