Is ArrayList.size() method cached?

后端 未结 7 1862
再見小時候
再見小時候 2020-12-31 02:58

I was wondering, is the size() method that you can call on a existing ArrayList cached? Or is it preferable in performance critical code t

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-31 03:33

    The obvious implementation of ArrayList would be to store the size internally in a field. I would be very surprised if it ever had to be computed, even after resizing.

提交回复
热议问题