It's a valid line if args
is declared as a String[][]
- but that wouldn't be how a main
method would be declared. length
is a valid member of an array, but it's not a (public) member of the String
class.
If you're trying to check the length of a string, you want the length()
method instead. For example:
if (args[0].length() > 2)
You might want to first check that there are some arguments, using args.length
. For example:
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("You need to give me an argument!");
return;
}
if (args[0].length() > 2) {
System.out.println("The first argument has more than 2 characters");
} else {
System.out.println("The first argument has 0-2 characters");
}
}