Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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:

enter image description here

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.

like image 953
Can Poyrazoğlu Avatar asked May 15 '15 15:05

Can Poyrazoğlu


People also ask

What is an ArrayList in Java?

ArrayList in Java is used to store dynamically sized collection of elements. Contrary to Arrays that are fixed in size, an ArrayList grows its size automatically when new elements are added to it. ArrayList is part of Java's collection framework and implements Java's List interface.

Is ArrayList List or array?

The ArrayList class is a resizable array, which can be found in the java.util package.

What is array and ArrayList?

Array and arraylist are well known data structures in Java programming language that are used to store the elements or objects. Arrays are basic functionality whereas Arraylists are collection frameworks in Java.


1 Answers

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.

like image 200
Oli Avatar answered Sep 21 '22 15:09

Oli