If I do args.length();
it is showing compilation error where as args.length is working fine.
but if it is not command line argument for eg. String str = "hello";
in this str.length
is not working but str.length()
is working fine.
please help!
Assuming you refer to the args
parameter of a main
method, that's because arrays do not provide a length()
method like String
s, but a length
public
property, returning int
.
See docs here .
String
as an object has a built in method called length()
Array
as an object does not have a built in method length()
, but it has a property called length
The parameter arg of the main method is an Array .
Arrays have a public property length
unlike Collections
or Strings
that have length()
method
The
public
final
fieldlength
, which contains the number of components of the array. length may be positive or zero.
There is no length()
method. Documentation .
String
class has a method called length()
( Docs )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.