Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

processing/java: cannot invoke length() on the array type boolean[] [duplicate]

Surprised that this wasn't already posted. I'm making a for loop, and its worked before but for some reason I can't find the length of a boolean array.

for(int z = 0; z < keyIsFound.length(); z++){
  //do something
}
like image 735
Muhammad Shahab Avatar asked Dec 09 '15 13:12

Muhammad Shahab


3 Answers

For arrays, their lengths are fixed when we create them. If you want to get the length of any array, use .length.

like image 182
Ankit Shubham Avatar answered Nov 08 '22 17:11

Ankit Shubham


.length = to get the length for arrays
.length() = to get the length of Strings

like image 28
Ruelos Joel Avatar answered Nov 08 '22 18:11

Ruelos Joel


For array the length is a property - not a method. You have to write keyIsFound.length. Array is a fixed sized data structure when you create an array like -

int[] nums = new int[10];

You actually fixed it length too.

like image 3
Razib Avatar answered Nov 08 '22 17:11

Razib