我得到了一些可爱的 Java 代码,其中有很多这样的东西(在一个执行大约 150 万次的循环中)。
code = getCode();
for (int intCount = 1; intCount < vA.size() + 1; intCount++)
{
oA = (A)vA.elementAt(intCount - 1);
if (oA.code.trim().equals(code))
currentName= oA.name;
}
我会看到从切换到类似以下内容的速度显着提高吗
code = getCode();
//AMap is a HashMap
strCurrentAAbbreviation = (String)AMap.get(code);
编辑:vA 的大小大约为 50。修剪不应该甚至是必要的,但调用它 50 次而不是 50* 肯定会很好150万。 vA 中的项目是唯一的。
编辑:在几位回复者的建议下,我测试了一下。结果在底部。谢谢大家。
最佳答案
只有一种方法可以找出答案。
关于Java优化,从hashMap中获益?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1650514/