Some of the important points to remember while using Java
Collections Framework are:
1. Interfaces: For Collections, we should write code with
generic interfaces instead of concrete implementation. Due
to this we maintain the flexibility of changing the
implementation at a later point of time.
2. Generics: We should use Generics for type-safety and to
avoid ClassCastException at runtime.
3. Collections: It is recommended to use Collections utility
class for algorithms and various other common methods
for Collections.
4. Right Type: We have to choose the right type of Java
collection based on our need. If size is fixed, we can use
Array over ArrayList. If we do not want duplicate
elements we use Set.
If we need the ability to iterate the elements of a Map in
the order of insertion then we use a TreeMap.
5. Initial Size: In some collection classes we can specify the
initial size/capacity. Therefore we should have an estimate
of number of elements in a Collection before deciding the
right collection type. We can use it to avoid rehashing or
resizing.
6. Map: We should use immutable classes provided by Java
as key elements in a Map