Your verification of a null array is not incorrect if it were not for the fact that the args array passed to the main function of the Java program is initialized by the JVM itself, so the array will never be null, it can be empty, but not null. The JVM ensures that the args array is initialized. Checking for null is still not erroneous, but it is redundant and makes little sense, especially it does not make sense that you gave it (no arguments are passed on the command line).
Since the array will always be initialized, you can be sure that it will be invalid and will only perform an empty check:
if(argsl.length == 0) {
And you can even iterate over the array directly without worrying about a NullPointerException:
for(String arg : args) { System.out.println(arg); }
aleroot
source share