size()如何在Java的ArrayList类中工作? [英] How does size( ) works in java's ArrayList class?
本文介绍了size()如何在Java的ArrayList类中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,为了获得最高效的代码,我真的很想知道Java ArrayList
中的size()
方法是如何工作的……它像每个简单的对象一样,对所有元素进行遍历所有位置吗列表?还是只是通过注册的最后一个索引获取大小?
So, in order to get the most efficient code, I really wanted to know how does the size()
method in Java ArrayList
work... Does it count every element, going through all the positions, like a simple list? or does it just gets the size by the last index registered?
提前谢谢!
推荐答案
It returns an instance variable - pretty damn fast.
这篇关于size()如何在Java的ArrayList类中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文