Java collections are similar to STL in C ++, which contains common data structures such as set, list, map, and queue. There are several main items: Set -- Focus on the uniqueness of the element, and all elements cannot be repeated List -- Focus on the element index, location Queue -- Focus on the element's inbound and outbound order Map -- Focus on the corresponding relationship of the element, the values can be repeated, but the keys cannot be repeated. However, these four are all interface classes. If you want to use them, you need to use their implementation classes. For the specific relationship, see: similar to STL, these collections also have some unified operation methods. The implementation here mainly uses the interface class. Another important thing is Iterator, which also exists in STL, Which is similar. Some common methods: Collection add -- add remove -- delete clear -- clear size -- size isEmpty -- whether it is empty contains -- whether it contains iterator -- Return iterator, used to traverse equals cyclically -- to judge equal, generally, it is used to determine whether the same one is used, do not compare the content hashCode -- hash code Listget -- get the element indexOf a certain position -- Obtain the element index several important classes and interfaces. The table above shows some advantages and disadvantages, when selecting a set, you can refer. A simple example is used to add and sort data: [java] List <String> list = new ArrayList <String> (); list. add ("B! "); // Add list. add ("! "); // Collect before sorting B. sort (list); // sort // List after sorting a B <String> list = new ArrayList <String> (); list. add ("B! "); // Add list. add ("! "); // Collect before sorting B. sort (list); // sort // [java] Map <Integer, String> map = new HashMap <Integer, String> (); map. put (1, "a"); Map <Integer, String> map = new HashMap <Integer, String> (); map. put (1, "a"); Array to list can use the asList method of Array. [Java] String [] sa = {"a", "B", "c", "d"}; List list = Arrays. asList (sa); String [] sa = {"a", "B", "c", "d"}; List list = Arrays. asList (sa); Iterator can be used for traversal. [Java] Iterator <String> it = list. iterator (); // traverse while (it. hasNext () {System. out. println (it. next ();} Iterator <String> it = list. iterator (); // traverse while (it. hasNext () {System. out. println (it. next ();} interesting things there is an interesting thing in java, which can easily traverse all elements, that is, the basic usage of for-each is as follows: [java] int [] a = {0, 2, 5, 3}; int nSum = 0; for (int n: a) // sum {nSum + = n; // n = 1; // This operation will not change the value in array a, because here n is "read-only"} int [] a = }; int n Sum = 0; for (int n: a) // Sum {nSum + = n; // n = 1; // This operation will not change the value in array a because here n is "read-only"} explained for (int n: ), int n indicates the element type and defines a temporary variable to save the element value. a indicates the array or set where the element is located, and then traverse from start to end. Of course, you can add process control statements such as break to the loop. Note that n here is "read-only", that is, even if you assign a value to n in the array, the value in the array a will not change, for example, if n = 1; is put into the statement, after the loop ends, the data in array a is still original and will not change to 1. Another interesting thing is equals and hashcode. Equals is a member function of the object. It mainly compares the two addresses that point to the same address. Normally, it does not compare the content. Do not make a mistake. However, some classes, such as int, double, and string, are reloaded, so they compare the content and can be used with ease. We recommend that you use equals instead of "= ". Because "=" may be incorrect, but equals does not. In addition, there is a hashCode, which is also a comparison, but it compares the hash code with different content, and the hash code may be the same. The above two may be used in map.