Currently working through some lectures on collections in Java. Definitely not the easiest subject in my opinion and apparently also an important subject for programming in general.

The interfaces for collections that are discussed are:

(in brackets the possible implementations that are discussed in the course)

  • List (f.e. ArrayList or LinkedList)
  • Set (f.e. HashSet, TreeSet or LinkedHashSet)
  • Map (f.e. HashMap, TreeMap or LinkedHashMap)

Some great learnings from this, besides learning about collections and their implementations, are:

  1. It finally stuck with me why you want to program to the interface instead of an implementation of that interface.
  2. There was a great reminder on casting (changing the type of an object to another type).
  3. Sometimes you will want to program to the actual implementation (f.e.: TreeSet instead of Set or ArrayList instead of List) because it can give you access to extra – implementation specific –   methods. For example the descendingIterator for a TreeSet which shows all the objects in your TreeSet in the reverse order.

Obviously in the lecture there are much more interesting topics regarding collections. Especially iterating through values in nested lists. Complex stuff (for now) and definitely a topic I want to spend more time on.

 

Some recommended reading on collections:

Oracle documentation on Collections is very interesting complimentary information on Java collections, available for free.

The lecture on collections I am talking about in this post is from CodersCampus. It is actually a part of the paid content.

Freely available is a podcast from the same author that discusses Java collections. I highly recommend this podcast. Not just for the collections episode but all the episodes.