LinkedList vs ArrayList on a specific android example
我从我的
1 2 | myList.add(myList.get(0)); myList.remove(0); |
目标硬件是Android操作系统。我应该以返回
MyList总是有100个元素
MyList总是有10个元素
也许我看到了一个没有问题的地方。在这种情况下,您认为我不应该关心性能,因为问题的大小(对于1和2)都很小?
我知道"过早的乐观是万恶之源"这句话。这就是为什么我在改变我的实现之前犹豫的原因(现在,我的
如果您经常添加/删除/更新元素,特别是对于第一个/最后一个元素,您应该使用
长应答
例如,从链接列表中删除一个元素需要花费
但是,这并不总是一个规则,正如Bigoh Post所说:
Big-oh notation can give very good ideas about performance for large amounts of data, but the only real way to know for sure is to actually try it with large data sets. There may be performance issues that are not taken into account by big-oh notation, eg, the effect on paging as virtual memory usage grows. Although benchmarks are better, they aren't feasible during the design process, so Big-Oh complexity analysis is the choice.
以上内容在本篇文章中得到了验证,其中
最后,根据javaconceptoftheday.com:,为了进一步/将来的参考,请看一下它们的用例比较。
参考文献
http://docs.oracle.com/javase/8/docs/api/java/util/linkedlist.htmlhttp://docs.oracle.com/javase/8/docs/api/java/util/arraylist.html