List is an interface and ListArray is a class. ListArray inherits and implements the List. So the List cannot be constructed, but you can create a reference to the List as above, and ListArray can be constructed. List list; / / the correct list = null; List list=new List(); List List = new ArrayList(); This creates an ArrayList object and traces it back to the List. Now it’s a List object, and some ArrayList has properties and methods that List doesn’t, so it can’t be used anymore. While the ArrayList list = new ArrayList (); Creating an object preserves all the properties of the ArrayList. Here’s an example: import java.util.*; public class TestList{ public static void main(String[] args){ List list = new ArrayList(); ArrayList arrayList = new ArrayList(); list.trimToSize(); // Error, there is no such method. arrayList.trimToSize(); //ArrayList contains this method. }} Compile to see the result. List a=new ArrayList(); A has all the properties and methods of List and ArrayList, If the List and ArrayList have the same attributes (such as int I) and the same methods (such as void f()), then a.i calls I in the List. — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — the key to the problem: List List = new ArrayList(), ArrayList = new ArrayList() The problem is that List has multiple implementation classes. Now you’re using ArrayList. Maybe one day you need to switch to another implementation class, such as LinkedList or Vector, etc. The rest of the code that uses lists doesn’t need to be changed at all. If you start with ArrayList alist = new ArrayList(), you’ll have to change that, especially if you use arrayList-specific methods and properties. List arr = new ArrayList(); Definition; ArrayListarr = new ArrayList(); Definition; The industry uses a special method called ArrayList. Private void doMyAction(List List){} This method can handle all classes that implement the List interface, partially implementing generic functions.

If the performance of ArrayList or HashMap does not meet your needs during development, you can customize your custom class by implementing List,Map(or Collection).