The two basic methods of interfacing with ---> are:
Iterator (): implements the Iterator interface; the next () method and the hasnext () method need to be combined;
the two method here is actually consistent with the nextElement and hasMoreElement methods of the enumeration interface,.
adds: for each () is translated as a loop with iterators, while the collection interface extends the iterator interface,
, so any collection of standard class libraries can use for each.
The principle explains that the Java iterator should be considered between two elements, and when the next method is called, the iterator passes the
The next element of , and returns the element that has passed (iterato.next and inputStream.read can be considered equivalent)
Iterator.next method must be called before iterator.remove (otherwise illegalStateException exception is thrown)
---->, because non abstract classes must implement all the methods in the interface, so
The Java class library provides a AbstractCollection abstraction class (which implements the collection interface)
Specific collection: (out of the class at the end of the Map, and the other classes implement the collection interface)
--->List interface (save elements in insert order)
-->ArrayList: is equivalent to an array that can automatically expand the size of the query, fast, slow additions and deletions, thread insecurity,
-->LinkedList: a two-way linked list, query slow, fast additions and deletions
***** implements the Queue interface, providing a variety of Queue and stack behavior
-->Vector: unlike ArrayList, thread security is
--->Set interface (cannot have duplicate elements) (primarily for testing attributes, contains)
-->HashSet: provide the fastest query speed
-->LinkedHashSet: saved in the insert order, and also provides quick access to the
-->TreeSet: keep the elements in sorted state (red black tree)
implements the Comparable interface
added: comparable interface and comparator interface distinction:
The ---comparable interface implements the default object comparison, the internal compareTo method,
The ---comparator interface declares the compare method of two display parameters, and can define the comparison object
--->Map interface (key value, equivalent to dictionary)
-->HashMap:key cannot repeat; the implementation of key is HashSet; allows the key or value of null;
-->Hashtable: thread safe, null key or value is not allowed;
-->TreeMap: keep the elements in sorted state (red black tree)
-->LinkedHashMap: double linked list, stored data is ordered.
-->WeakHashMap: once a object with a weak reference is found, the memory.
is recovered regardless of the current memory space
, however, since garbage collector is a low priority thread, it is not always quick to find objects that are only weakly referenced.
The weak reference can be used in conjunction with a reference queue (ReferenceQueue) if the object referenced by the weak reference is garbage collected,
The Java virtual machine adds this weak reference to the reference queue associated with it,.
-->Properties::key, and value are all String types used to read configuration files;
-->PriorityQueue: a typical example (task scheduler)
****** uses a heap structure, that is, a self - adjusting two - fork tree (always the minimum in the root),
--->Enum classes (Set and Map interfaces are implemented separately)