【发布时间】:2021-12-20 10:40:38
【问题描述】:
我有一个数组列表
[Type 1970, Type 1981, Type 1985, Type 1999]
[Type 1985, Type 1970, Type 1985, Type 1999]
[Type 1999, Type 1981, Type 1985, Type 1970]
[Type 1981, Type 1985, Type 1999, Type 1970]
[Type 1985, Type 1970, Type 1981, Type 1999]
我想拆分这些数组,同时仅提取特定模型类型(例如“Type 1999”)并提供计数。
这是我迄今为止想出的:
int counter = 0
for(int i = 0; i < listOfTypes.length; i++){
String[] typesSearch = listOfTypes[i]
if(typesSearch != null) {
if(typesSearch.equals("Type 1999")); {
counter++;
}
}
理想情况下,输出将是一个只有特定元素的新数组
{1999 型、1999 型、1999 型、1999 型} 等等
我想从这里我可以使用 length() 来获取这个新创建的数组中元素的计数
【问题讨论】:
-
typesSearch.equals("Type 1999")将始终返回false,因为其中一个是String[],另一个是String。他们永远不可能平等。