Today is the first day of school, according to the lecture progress of the previous semester, it should be possible to start learning multithreading, but because of the teacher, may transfer a bit in and out, and give us a lecture on the Java object container, so this is why the topic for "re-learning."
This article directory:
- Main uses of the collection
- Single value class Collection: List class and set class
- Key-value pairs class collection: Map class
The main use of collections: collections are mostly used when querying data is returned. For example, to use JSP to do a student information management system, you need to return from the database to query the results of students, put these results into a collection, and then return through the method, in the display layer (view) can use JSP tags to display them.
Single-Value class collection: The single-value class collection consists of list and set, both of which inherit from the collection root interface. In these two large interface classes can be subdivided into several classes to implement the interface, mainly some of these:
List
|
Advantages |
Disadvantages |
Characteristics |
ArrayList |
Easy collection for quick random access |
Removal efficiency is low |
Asynchronous |
LinkedList |
Easy to insert and delete objects |
Low random access efficiency |
----- |
List iterations: The iteration list can be iterated with the Get (Index) method, or by using the enhanced for loop foreach, or by using iterators.
Set
|
|
|
TreeSet |
Ordered, natural numbers are ordered, but the comparable interface must be implemented, overriding the Comoareto () method. |
Non-repeatable |
HashSet |
Unordered, based primarily on equals and hashcode to determine whether the same object |
Non-repeatable |
|
|
|
Set iterations cannot use the Get method and can be traversed using iterators and enhanced for loops.
Map
In class, the main HashMap, it is a set of key-value pairs, key keys are not allowed to repeat, a key can only correspond to one value, but a value can correspond to more than one key. Used to pass data between different pages. For example, the use of Request.setattribute ()/getattribute () in JSP is implemented using this kind of collection.
HashMap there is a method EntrySet () worth mentioning.
EntrySet ()
This method returns an attempt to set the mappings contained in this map, which, in layman's terms, is the set (contained in set) of an entity with a pair of <K,V> that can iterate over each HashMap entity using the iterative set method.
=========================end=================
The first blog feel Good egg pain, use is window Live Writer, code also did not post, the figure is not, a few sentences on the end, the total feeling that this editor is not so handy, as word, written like eating flies as not smooth, I am not suitable for blogging? Something so big on that.