Question: > 
> **Possible Duplicate:**  
> 
> [Type List vs type ArrayList in Java](https://stackoverflow.com/questions/2279030/type-list-vs-type-arraylist-in-java) 
> 
> 
> 

Why is it recommended to do this:

```
List<String> myArrayList = new ArrayList<String>

```

or same with Map interface and HashMap class

rather than:

```
ArrayList<String> myArrayList = new ArrayList<String>

```

Answer: 
Because the consuming code of the `myArrayList` variable won't be tied to a particular implementation of this interface.
With the first (preferred) line you say, that your code needs a List, with the second line you say your code needs an ArrayList. Usually, you path variable instances around. If you now change the myArrayList instance for some reason you would have to change too much code.