Why the size of the arrayList choice is 5 when all the elements have been set to null Answer Because the ArrayList still contains 5 Objects. They are null, but they are objects, thus present in the list! You can empty the ArrayList, by calling choice.clear();
Tag: null
How to simplify a null-safe compareTo() implementation?
I’m implementing compareTo() method for a simple class such as this (to be able to use Collections.sort() and other goodies offered by the Java platform): I want the natural ordering for these objects to be: 1) sorted by name and 2) sorted by value if name is the same; both comparisons should be case-insensitive. For both fields null values are