A figure shows the Java Collection classes (summary of the Java Collection classes) and the java
There are a lot of articles about Java Collection classes, but I recently saw a very interesting image, basically showing the overall framework of Java collections, which is very intuitive.
If you find that the image is not clear, click here to view the big picture.
Here, the Collection class is divided into two major categories: Map and Collection.
The four gray classes (Dictionary, HashTable, Vector, and Stack) in the upper left corner of the image are thread-safe, but they are all legacy classes of JDK, at present, there are almost no replacement classes. Here, Map is used to replace the Dictionary abstract class in the upper left corner of the image (which is described in the official Map document ). We recommend that you use the Map interface instead. For HashTable, ConcurrentHashMap is officially recommended. The following Vector is an implementation class under List.
Next, the top pink part is the relationship between all interfaces of the Collection class. The structure of Map is relatively simple, and the structure of Collection is relatively complicated. Collection has three inheritance interfaces: List, Queue, and Set.
The following green section is the main implementation class of the Collection class. This is also the most frequently used collection class.
FollowImplementation InterfaceCategory:
Map interfaces include EnumMap, IdentityHashMap, HashMap, LinkedHashMap, WeakHashMap, and TreeMap.
The List interfaces include ArrayList and rule List.
The Set interfaces include HashSet, javashashset, and TreeSet.
The following Queue interfaces are implemented: PriorityQueue, Queue list, And ArrayQueue
AccordingUnderlying data structureCategory:
The underlying layer is implemented in the form of Arrays: EnumMap, ArrayList, and ArrayQueue
The underlying layer is implemented in the form of a linked list: javashashset, shortlist, and javashashmap.
The underlying implementation is in the form of hash table: HashMap, HashSet, LinkedHashMap, LinkedHashSet, WeakHashMap, IdentityHashMap
The underlying layer is implemented in the form of red and black trees: TreeMap, TreeSet
The underlying layer is implemented in the form of a binary heap: PriorityQueue
The entire block at the bottom is the class in the java. util. concurrent package. According to the package name, we can know that the class in this package is used to process various concurrent scenarios in Java programming.
Next article: give a more detailed explanation of common collection classes in the middle (Common Implementation classes in the green part.
Recommended tools: http://grepcode.com /. Read code artifacts. This source code reading site not only contains the vast majority of Java class library source code, but also has been well optimized for comments and jumps in the middle of the source code. With it, ensure that your source code reading efficiency is greatly improved.
Source image: http://pierrchen.blogspot.com/2014/03/java-collections-framework-cheat-sheet.html
Write a collection class Java
Import java. util. ArrayList;
Import java. util. List;
Public class ListTest {
Public static void main (String [] args ){
List list = new ArrayList ();
For (int I = 0; I <10; I ++ ){
List. add (I); // add
}
// Delete the element whose subscript is 1
List. remove (1 );
// Change the value of 5 to 8.
For (int I = 0; I <list. size (); I ++ ){
If (Integer) (list. get (I) = 5 ){
List. set (I, 8 );
}
}
For (int I = 0; I <list. size (); I ++ ){
System. out. print (list. get (I) + "\ t ");
}
}
}
OK...
Just written...
Good luck ..
In Java, how can a set of a class exist in another class query all
If the Message class is defined as follows:
Public class Message {
Private List <MessageToUser> messageToUsers;
Public List <MessageToUser> getMessageToUsers (){
Return this. messageToUsers;
}
}
After obtaining the message:
List <MessageToUser> messageToUsers = message. getMessageToUsers ();
For (MessageToUser messageToUser: messageToUsers ){
// Operate messageToUser
}