In my code I default to using ArrayList for all Lists, HashMap for all maps, HashSet for all sets.
From a practical standpoint how much am I losing in flexibility, scalability, readability and performance by choosing the wrong implementation? When does it make sense to spend time to decide to use one rather than another?
I certainly see a very clear cut case for why someone would use a LinkedList instead of an ArrayList given certain circumstances. When does someone feel that it is critical they use a HashMap rather than a TreeMap or a HashTable? What about Sets?
Questions:
- What is the cost of choosing poorly?
- Does anyone have an disaster stories about choosing the wrong implementation and the datacenter catching fire?
- Any good rules of thumb?
- Are there any obscure collections implementations you can't live without?
I've read through:
- http://java.sun.com/j2se/1.4.2/docs/api/java/util/TreeMap.html
- http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html
- http://stackoverflow.com/questions/896139/java-arraylist-for-list-hashmap-for-map-and-hashset-for-set etc...
I found this question to be related from a theoretical point of view, but I'm more interested in a real world, down in the trenches answer.