I am new to java and when I go through the code of many examples on net I see people declaring the variable for an ArrayList as simply List in almost all the cases.
List<String> myList = new ArrayList<String>();
I don’t understand if there is some specific advantage of doing this. Why can’t it be an ArrayList itself, like so:
ArrayList<String> myList = new ArrayList<String>();
It’s called programming to an interface. It allows you to substitute that
ArrayListfor aLinkedListif somewhere down the line you decide that aLinkedListwould be more appropriate.