我有一个不占用大量内存的 ArrayList,它只存储两个字段,
public class ExampleObject{
private String string;
private Integer integer;
public ExampleObject(String stringInbound, Integer integerInbound){
string = stringInbound;
integer = integerInbound;
}
我将用这些对象填充 ArrayList
ArrayList<ExampleObject> = new ArrayList<ExampleObject>();
对于原始的硬核性能,使用哈希集是否会更好?如果我的 ArrayList 增长到具有数百个索引的大量项目,我会注意到对象的 ArrayList 和哈希集之间存在巨大差异吗?
最佳答案
虽然它们都是Collection ,我建议您阅读 Set 之间的差异和一个List 。
它们的用途不同。因此,在考虑性能之前,请选择满足您的实现要求的方案。
关于java - 原始硬核性能,对象的 ArrayList 与哈希集比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14582779/