Someone who is just starting with Java programming language often has doubt about how we are storing an ArrayList object in List variable, what is the difference between List and ArrayList? or why not just store the ArrayList object in ArrayList variable just like we do for String, int, and other data types. Well, the main difference between List and ArrayList is that List is an interface while ArrayList is a class. Most importantly, it implements the List interface, which also means that ArrayList is a subtype of List interface. In Java or any object oriented language, super type of variable can store an object of subtype. This is known as Polymorphism because any virtual method will be executed from subclass only, even though they were called from super type. This is the beginning, now let's see those two questions as well.
Read more »