Reputation: 275
How do i read a file and determine the # of array elements without having to look at the text file itself?
String temp = fileScan.toString();
String[] tokens = temp.split("[\n]+");
// numArrayElements = ?
Upvotes: 0
Views: 14343
Reputation: 62864
Use the length
property of the array:
int numArrayElements = tokens.length;
Upvotes: 5
Reputation: 16987
The proper expression is tokens.length
. So, you can assign numArrayElements
like this:
int numArrayElements = tokens.length;
This counts the number of elements in the tokens
array. You can count the number of elements in any array in the same way.
Upvotes: 2