Loading topic
int are not objects. This chapter shows how Java lets you store numbers in a collection anyway, and covers one mistake that catches many beginners.2 min readArrayList. Java has a second list type called LinkedList. Both follow the List interface. An interface is a set of methods a class promises to have. So both types have add, get, set, remove, and size. They store their elements in different ways, and that changes how 2 min readequals and hashCode. This chapter shows how those methods work, so the s2 min readSet handles that.2 min readComparable and Comparator.2 min readHashSet keeps each element only once, but it makes no promise about order. If you print it, the elements can come out in any order. Sometimes you need unique elements and a predictable order as well. Java gives you two more Set implementations for this.2 min readsize(). Instead, the map gives you three views of its contents. A view is a collection that looks into the map without copying it.2 min readHashMap finds values fast, but it does not promise any order. When you print it or loop over it, the keys can come out in any order. Sometimes order matters. You may want keys in the order you added them, or in sorted order. Java gives you two maps for this, and both implement the same Map int2 min read