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?
Thanks in advance!
Never hurts to look in the source code:
public int size() {
return size;
}
It returns an instance variable - pretty damn fast.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With