I am making a calculator and I converted the string to a char array using
char[] b = inputString.toCharArray();
(inputString is my String variable)
Since String is the input, I don't know how big the array will be. Is there a built-in method that allows you to find the number of elements in an array? Thanks in advance.
You can use b.lengthto find out how many characters are.
b.length
This is just the number of characters, not indexing, so if you iterate over it with a loop for, remember to write it like this:
for
for(int i=0;i < b.length; i++)
< ( <=). , , length , .
<
<=
length
, !
static int length(final char[] b) { int n = 0; while (true) { try { int t = b[n++]; } catch (ArrayIndexOutOfBoundsException ex) { break; } } return n; }
( ... b.length.)
b.length -
length array.
. , - , ( - ), ( ).
inputString.length()
. . , arrayRefVar.length. , myList.length 10.
arrayRefVar.length
myList.length
b.length; very convenient and very useful to find the length of the char [] array :)