Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何读取文件并确定数组元素的 # 而无需查看文本文件本身?
String temp = fileScan.toString(); String[] tokens = temp.split("[\n]+"); // numArrayElements = ?
使用length数组的属性:
length
int numArrayElements = tokens.length;
正确的表达方式是tokens.length。所以,你可以这样分配numArrayElements:
tokens.length
numArrayElements
这会计算tokens数组中元素的数量。您可以以相同的方式计算任何数组中的元素数。
tokens