Java is a set of very mature things, a lot of commercial things are like to use it, with more people, stable. But generally not talk about it, because it is too common, in private, write Java application layer is like a peasant worker, each place is building blocks, according to the designer's things how to build a good building blocks, of course, the beauty of its name, on the peasant workers to build the art of building blocks. Not difficult, but a lot of things, experience in the inside is a very important thing. The above is purely daily nonsense, laugh to see, after all, I am now a Java programmer slag.
The Java Collection framework is based on the collection interface, which defines the basic framework, including the size, hashcode, iterator, add, AddAll, remove, Retainall, ToArray, clear, and so on. That is, all the classes that implement this interface must have these methods. How is this set of frames organized? Collection interface defines the large framework, abstractcollection as the implementation of the Collec interface of the abstract class, but also implemented a number of methods, but there is no size and other methods of implementation, this is called the basic class, to help do some work, and then some specific implementation class. Collection under the comprehensive can see another three kinds, set and list and queue these three kinds, generally we use list most, set second, queue with the least, of course, this also has a great relationship with our life.
List is a sequence of allowed to repeat the class data structure, that is, the data in the order of the inside, such as Take List.get (i) to get an object, where the list does not care about the value of each element is the same, the general constructor of the list is list<string > list = new arraylist<string> (), where generics are used, and the elements to be accessed by the list are defined at compile time. List is also an interface, generally we use implementation class ArrayList to get the object. The list is dynamically growing. In addition, the list can also be converted to an array, using the ToArray method, can be more convenient to convert to array.
Set does not allow repetition is a collection data structure that has no order. General set we see the most implementation class is HashSet (the guest rate is generally 0.75, the initial capacity is 16, once more than doubled), with a hash to achieve a good efficiency. In general, each of the same object has the same hash value, this is defined in the object method, different objects may also have the same hash value, this need to do some special processing. Set because it is a hash to achieve, so there is no guarantee to add into the set order, this time you can consider using the Linkedhashset class to handle, Linkedhashset class when the Add method is added, When printing can guarantee that the order of printing and the order of the original added is the same, HashSet is not guaranteed. There is also a class is TreeSet, tree set, this in some of the above interface and abstract class to do bedding, there are several special methods, such as Head,tail,ceil,floor and other methods ceil is the meaning of the ceiling, greater than equals, floor floors, so it is less than equals. With these, there is a sort of class meaning, that is, the TreeSet class can guarantee that the elements inside are sorted in some order. So in the TreeSet constructor can see the comparator class parameters, TreeSet also accept the common set class, but the order of the two are not the same. Speaking of the principle of sorting, there are generally two, one is the natural sort, the other is to implement the comparator interface according to the user's own definition of a sort of method. Comparator interface, generally there is a compare method need to rewrite, and then give the return value, parameter is passed the interface object containing comparator, if return 1 is greater than, return 0 means equal, return 1 means less than.
The queue is used less, and is a first-in-one-out. (To be continued, pending Amendment)
One of the collection frameworks for Java