ArrayList#size() is more than actual number of objects

南笙酒味 提交于 2019-12-23 06:48:42

问题


I have an ArrayList in my Android app, and it has 2 items in it. However, its size method returns 3. I know it sounds really simply and stupid, but here is how it goes:

Why would this happen? How can an ArrayList's size return an incorrect number? This causes a null pointer exception when I'm iterating the list.


回答1:


IntelliJ has a setting about hiding null values. Right click the variables section in the debugger and choose Customize Data Views.... There is an option there for Hide null array elements that you should make sure is unticked.



来源:https://stackoverflow.com/questions/30262906/arraylistsize-is-more-than-actual-number-of-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!