Possible Duplicate:
Isn't it easier to work with foo when it is represented by the class ArrayList rather than the interface List?
Why are most of the examples using ArrayList
Why do we mostly do, like this :
Map<Integer, String> map = new HashMap<Integer, String>();
instead of :
HashMap<Integer, String> map = new HashMap<Integer, String>();
& similar while instantiating ArrayList(s).
Less typing, Map is the Interface (same with List) for that class so it’s easier to pass a Map around than a HashMap since the functionality is the same the only difference is the implementation. This is usually done (in some cases) when lets say for some reason you decide that HashMap isn’t what you want and you want to use TreeMap instead but in all of your code there’s HashMap parameters and changing those can be a pain. If you pass Map instead you don’t have to change anything and your code can be a lot more flexible.