You want to use the most narrow type to do stuff with that type as it documents your usage better. A coder might wonder, "What method particular to an ArrayList is he using?" For example, if your code only uses .size(), you should use Collection instead of List or ArrayList. However, you want to return from a method with the most specific type you can always guarantee as it gives the user of that API more freedom to apply needed methods on that data. You should use List whenever all you need is defined on the List API. Consider using Collection or even Iterable if possible.
Additionally, if an interface and a concrete type implement the same methods, you should prefer to use the type that is most appropriate based on a need to know basis in the class using that type. If your class truly relies on a List being implemented by ArrayList, you should use the latter. If it doesn't, you should use the former. This is a form of self-documenting code. The right type is the least specific as it restricts what can be done with it / how much to know about it, leading to an easier ability to understand what is happening.
ArrayListis he using?" For example, if your code only uses.size(), you should useCollectioninstead ofListorArrayList. However, you want to return from a method with the most specific type you can always guarantee as it gives the user of that API more freedom to apply needed methods on that data. You should useListwhenever all you need is defined on theListAPI. Consider usingCollectionor evenIterableif possible.Listbeing implemented byArrayList, you should use the latter. If it doesn't, you should use the former. This is a form of self-documenting code. The right type is the least specific as it restricts what can be done with it / how much to know about it, leading to an easier ability to understand what is happening.