【发布时间】:2016-04-04 11:47:49
【问题描述】:
我正在尝试查找数组列表中条目项的相应值(字母数字值及其哈希码)。
已放弃使用 hashmap 以允许复制对象(键)。
ArrayList<Object[]> pNArrayList = new ArrayList<Object[]>(); 包含
[101E2571G103, -1162488899]
[101E2571G103, -1162488899]
[116E3139P001, -1561106156]
[314B7159G003, -1344220682]
[117E3640G025, -1595019143]
[117E3640G025, -1595019143]
对于输入,inputID 类型为 long
for(int i=0; i< pNHashArrayList.size();i++) {
if(pNArrayList.get(i)[1].equals(inputID)){
System.out.println(pNArrayList.get(i)[0]);
}
else {
System.out.println(pNArrayList.get(i)[0] + " and "+ pNArrayList.get(i)[1] +" No Match Found");
}
}
此后的else 和SysOut 语句仅用于交叉验证。
输出:
101E2571G103 and -1162488899 No Match Found
101E2571G103 and -1162488899 No Match Found
116E3139P001 and -1561106156 No Match Found
314B7159G003 and -1344220682 No Match Found
117E3640G025 and -1595019143 No Match Found
117E3640G025 and -1595019143 No Match Found
我认为,问题可能出在pNArrayList.get(i)[1].equals(inputID)?。需要对此提出一些建议。
另外,我的实际数据集将有大约 10,000 个整体,通过循环进行查找是否会对运行时计算产生问题?
【问题讨论】:
-
同时打印Sysout中
inputID的值,进一步调试为什么不等于pNArrayList.get(i)[1]。 -
@Mahendra
inputID是-1595019143,它实际上存在于 ArrayList 中。这是我无法理解问题的地方。
标签: java loops arraylist data-structures