ArrayList or List declaration in Java
问题 What is the difference between these two declarations? Declaration 1: ArrayList<String> arrayList = new ArrayList<String>(); Declaration 2: List<String> arrayList = new ArrayList<String>(); 回答1: List<String> arrayList = new ArrayList<String>(); Is generic where you want to hide implementation details while returning it to client, at later point of time you may change implementation from ArrayList to LinkedList transparently. This mechanism is useful in cases where you design libraries etc.,