Java collections and Arrays
Reprinted from: http://www.cnblogs.com/summers/p/4094260.html
Differences between Array and set: (1) arrays are fixed in size, and the same Array can only store data of the same type (basic type/reference type) (2) a java set can store a set of data with an unfixed number of operations. (3) If the program does not know how many objects are required and the capacity needs to be automatically expanded when the space is insufficient, the container class library is required. array is not applicable. Contact: Use the corresponding toArray () and Arrays. asList () Methods to recall the conversion. 1. architecture of the Collection: List, Set, and Map are the three most important interfaces in this collection system. List and Set inherit from the Collection interface. Map also belongs to the Collection system, but it is different from the Collection interface. Set does not allow repeated elements. HashSet and TreeSet are two main implementation classes. The Set value can only be Set through the cursor, and the value cannot be repeated. The List is ordered and repeated elements are allowed. ArrayList, Vector list, and Vector are three main implementation classes. ArrayList is thread-unsafe, and Vector is thread-safe. The underlying layers of these two classes are all implemented by arrays. The worker list is thread-unsafe, at the underlying layer, Map implemented by the linked list is a set of key-value pairs. The key column is a set, and the key cannot be repeated, but the value can be repeated. HashMap, TreeMap, and Hashtable are the three main implementation classes of Map. HashTable is thread-safe. It is not thread-safe to store the null value HashMap. It can store the null value. difference between List and ArrayList 1. list is an interface, and the List feature is ordered. It ensures that elements are saved in a certain order. arrayList is its implementation class. It is a List implemented by arrays. map is an interface, and the Map feature is to find objects based on an object. hashMap is its implementation class. HashMap uses the Map implemented by the hash table to perform Fast hash search using the hashcode () method of the Object. (For more information about hash search, see <Data Structure>) 2. in general, if not necessary, the recommended code only deals with the List and Map interfaces. for example: List list = new ArrayList (); the reason for this is that list is equivalent to a generic implementation. To change the list type, you only need: list list = new rule List (); // rule List is also the implementation class of list, which is also the brother class of ArrayList. No other code needs to be modified. This is the elegance of interface programming. in addition, in the method of the class, the following declaration: private void doMyAction (List list) {}. In this way, this method can process all classes that implement the List interface, to some extent, generic functions are implemented. 3. if you think that the performance of ArrayList and HashMap cannot meet your needs during development, you can customize your custom classes by implementing List, Map (or Collection.
3. Illustration:
int[] m = { 1, 2, 3 };String[] strings = { "aaa", "bbb" };List<String> list = new ArrayList<String>();List<Integer> lists = new ArrayList<Integer>();List<Map<String, Object>> list2 = new ArrayList<Map<String,Object>>();List<City> listcity = new ArrayList<City>();