开发者

How to determine the number of the input arguments in Java

开发者 https://www.devze.com 2023-04-09 06:01 出处:网络
Is there some methods to determi开发者_如何学JAVAne the number of input arguments from console 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

精彩评论

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