Java Java Objects Delivering the MVP Arrays and Command Line Arguments

Wan Nor Adzahari Wan Tajuddin
Wan Nor Adzahari Wan Tajuddin
2,433 Points

Why no () needed on args.length == 0

Isn't .length is a method? Therefore it should have been .length() instead of .length ?

if (args.length == 0) { \\ Why is it args.length and not args.length() System.out.println("Usage: java Hangman <answer>"); System.err.println("Answer is required"); System.exit(1); }

2 Answers

Fahad Mutair
Fahad Mutair
10,340 Points

In addition to what Rune said

length is used with Arrays

length() is used with String

Rune Andreas Nielsen
Rune Andreas Nielsen
5,252 Points

Hi, Wan.

In Java, length is a property on the Array Type. Properties cannot be called by using the '()' syntax in Java.