你如何确定字符串数组java的大小?

时间:2021-06-29 07:15:51

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 = ?

2 个解决方案

#1


5  

Use the length property of the array:

使用数组的length属性:

int numArrayElements = tokens.length;

#2


2  

The proper expression is tokens.length. So, you can assign numArrayElements like this:

正确的表达是tokens.length。因此,您可以像这样分配numArrayElements:

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.

这会计算标记数组中的元素数。您可以以相同的方式计算任何数组中的元素数。

#1


5  

Use the length property of the array:

使用数组的length属性:

int numArrayElements = tokens.length;

#2


2  

The proper expression is tokens.length. So, you can assign numArrayElements like this:

正确的表达是tokens.length。因此,您可以像这样分配numArrayElements:

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.

这会计算标记数组中的元素数。您可以以相同的方式计算任何数组中的元素数。