Java provides several ways to hold objects, including language built-in Array, as a container classs, also known as a Collection ClassES. The collection is very important in Java. Before discussing, first look at the classic issues in several interviews. 1 COLLECTION and COLLECTIONS. 2 LIST, SET, MAP inherits from the Collection interface. 3 ARRAYLIST and VECTOR differences. 4 HashMap and Hashtable distinction. There is an answer from the tail, we start the topic.
Collection Collection Interface - Collection is any object group, the elements are independent, usually have the same set of rules. Set List is derived from it. Basic Operation Add Element Add (Object Obj); Addall (Collection C); Deleting Element Remove (Object Obj); Removeall (Collection C); Trying to Retainall (Collection C);
A good way to access / traverse the collection element is to use the Iterator interface (iterator for replacing ENUMERATION) public interface itrator {public boolean hasnext (0; public object next (0; public void remove)
Set SET - There are three specific types of specific types of sets that have three specific types of set available HashSet-based sets, and the elements of the hash table are added to implement the Hashcode () method LinkedHashSet - Return to the elements in the order of adding order. Data structure based on (balance) tree
List List - Location Collection. The elements of adding lists can be added to a specific location in the list or there are two specific versions arraylist (array tables) similar to the Vector, which are used to scale an array maintenance collection. Difference: First. Synchronization: Vector is a thread safe, that is, the ArrayList is unsafe, not synchronized, data growth: When you need to grow, the Vector default growth is the original training, ArrayList is the original half LinkedList (Lin table) - is a two-way linked list, each node has two pointers pointing to a node and the next node. Used in FIFO, add Element RemoveFirst () to use addList () to use AddFirst () / removelast () ProvIOS (), delete, replace, add an element
Map table MAP - For keyword / value pairs, three collection key sets of Dictionary Processing MAP KeySet () Set Value () ENRYSET () Four Specific Version HashMap - General Map Table of List LINKEDHASHMAP-Extended HashMap, maintenance Insert Sequence WeakHashMap-Based on the Map of Based on the Flat Stickers, the memory recycling program will recover its TreeMap-based tree-based Mapping table
Collections class, used for synchronization set, can also change the collection of read-only mode class EG: Map Mp = new hashmap () mp = collections.synchronizedMap (MP); // Generate thread security mapping table MP = Collectes.unmodiFiableMap (MP) ); // Generate read-only mapping table
Comparable Natural Order Sort COURPARATOR Tree Collection Sort
Container Taxonomy Collection Interface: Collection List Set; Map Iterator ListIterator. Abstract class: AbstractCollection AbstractList AbstractSet AbstractMap AbstractSequentialist. Implementationshash TableresiZable ArrayBalanceTHashSettreeSetlista SetetHashSettreesetListarrayListLinkedListMaphashmaptreeMap Old Version Set Type VectOR Class Vector. A heterogeneous mixture can dynamically increase capacity. For its operation, the following is, for example, we have a vector: vector myvec = new vector (a_array.Length) gets the length of the vector: MyVec.Size (); assignment: set (int position, object obj) / setElementat (Object Obj, int Position) - Dynamic growth add (object obj) / addElement (Object Obj) Add Object EG: MyVec.Add (New A_Array [0]); Removal Element: Get (int position) / getElement (int position)
The Stack class is the subclass of the Vector. It is the stack whose data structure (this word can be referred to, don't be confusing with Heap- Heap). The next step is the way. Stack () Construct Empty Empty () Recreation Search () Check the Stack Have Element PEEK () Getting Stack Top Element Pop () Shot Push () Finding
ENUMERATION interface
Dictionary class dictionary. Key words / numeric way access data, if the mapping does not have this keyword, retrieve the NULL.
The HashTable class is the specific implementation of the Dictionary structure.
The difference between the on-site answering answer Collection and Collectes. Collections is a class under java.util that contains a variety of static methods related to the collection. Collection is an interface under java.util, which is a parent interface of a variety of collections. List, SET, MAP inherits from a Collection interface? List, SET is Map is not the difference between arraylist and vector. I. Synchronization: Vector is a thread safe, that is to say is synchronized, and ArrayList is unsafe, not synchronized. Data growth: When you need to grow, Vector default growth to the original one, and arraylist It is the difference between Hashmap and HashTable. History: HashTable is an implementation of an old Dictionary class. Hashmap is an implementation of the MAP interface introduced by Java 1.2. Synchronism: Hashtable is thread security, that is, Synchronous, and havehmap is unsafe, not synchronized, not synchronized. Value: Only HashMap allows you to take null value as a key or value of a table