【发布时间】:2014-08-11 02:33:47
【问题描述】:
我有大量可以存储在 HashSet 或 String 中的 ID 即
String strIds=",1,2,3,4,5,6,7,8,.,.,.,.,.,.,.,1000,";
Or
HashSet<String> setOfids = new HashSet<String>();
setOfids.put("1");
setOfids.put("2");
.
.
.
setOfids.put("1000");
我还想对 ID 执行搜索
我应该使用哪个以获得更好的性能(更快和内存效率)
1) strIds.indexOf("someId");
or
2) setOfids.contains("someId");
告诉我任何其他方式,我也可以这样做。 谢谢你看这里:)
【问题讨论】:
-
哈希集是要走的路!
标签: java string search collections hashset