Home > Back-end >  Array traversal traversal with length attribute and string with the length of the difference of ()
Array traversal traversal with length attribute and string with the length of the difference of ()

Time:12-06

I've just started today when traversing the String with the String variable name. Length to determine the length of the String, the run time give me a mistake, but I had in The Times when the array length is used to determine the length of the array error, because without the length of the String class attribute his only length () method to determine the length of the String so when can only use the length () method and array length this attribute,

for(int i=0; iIf (I==arr. Length - 1) {
S +=arr [I];
Can't find the symbols
If (I==arr. Length () - 1) {
^
Method of symbol: length ()
Location: type to int [] variable array arr just with this method will be an error with the above is ok,

CodePudding user response:

The length attribute is for Java arrays in, ask the length of the array may use its length attribute;

Length () method is to the string, request the length of a string to use it the length () method;

You arr is an array, the applications you use arr. The length can be array length, arr. The length () in the arr is an array, if the arr. The length () to arr [I] length () should not be an error,

CodePudding user response:

String is the wrapper class, it is only the length () method to obtain the length,
  • Related