Java Collection framework diagram and introduction

Source: Internet
Author: User
Tags addall

Simplified diagram:

The Java platform provides a new collection framework. The set framework consists of a group of interfaces used to operate objects. Different Interfaces describe a set of different data types.


Framework of Java 2 sets

Set interface: Six interfaces (short dotted line), indicating different set types, is the basis of the set framework.

Abstract class: Five abstract classes (long dotted line) are used to implement part of the set interface. Can be expanded to custom collection classes.

Implementation class: Eight implementation classes (Real-line representation), specific implementation of the interface.

To a large extent, once you understand the interface, you understand the framework. Although you always need to create interface-specific implementations, the methods used to access the actual set should be restricted to the use of interface methods. Therefore, you can change the basic data structure without changing other code.

· The collection interface is a set of objects that can be repeated.

· The set interface inherits collections but does not allow repeated operations. It uses an internal arrangement mechanism.

· The list interface inherits collection objects and allows repeated elements to be placed in the order of element insertion without re-arrangement.

· The map interface is a key-value object consisting of a pair, that is, it holds key-value pairs. Duplicate keys are not allowed in map. Has its own internal arrangement mechanism.

· The Element Types in the container are all objects. When getting an element from a container, you must convert it to the original type.


Java 2 simplified set framework

Set Interface

1. Collection Interface

Indicates any object or element group. This interface is used when you want to process a group of elements in a regular way as much as possible.

(1) add or delete a single element:

Boolean add (Object O): adds an object to a set.

Boolean remove (Object O): If the set contains objects that match o, delete the object o

(2) query operations:

Int size (): returns the number of elements in the current set.

Boolean isempty (): determines whether any element exists in the set.

Boolean contains (Object O): searches for whether the set contains object o

Iterator (): returns an iterator used to access each element in the set.

(3) group operation: acts on the element group or the entire set.

Boolean containsall (collection C): checks whether the collection contains all elements in set C.

Boolean addall (collection C): Adds all elements in set C to this set.

Void clear (): deletes all elements in a collection.

Void removeall (collection C): removes all elements in collection C from the collection.

Void retainall (collection C): Removes elements not included in set C from set

(4) convert collection to object array:

Object [] toarray (): returns an array containing all elements of the set.

Object [] toarray (object [] A): returns an array containing all elements of the set. The array and parameter a returned at runtime are of the same type and must be converted to the correct type.

In addition, you can convert a set to any other object array. However, you cannot directly convert a set to an array of the basic data type, because the set must hold objects.

The ITALIC interface method is optional. Because an interface must implement all interface methods, the caller needs a way to know whether an optional method is not supported. If an unsupportedoperationexception is thrown when an optional method is called, the operation fails because the method is not supported. This exception class inherits the runtimeexception class, avoiding putting all set operations into try-catch blocks ."

Collection does not provide the get () method. To traverse the elements in Collectin, you must use iterator.

1.1.20.actcollection abstract class

The abstractcollection class provides the basic functions of the specific "collection framework" class. Although you can implement all the methods of the collection interface on your own, except that the iterator () and size () methods are implemented in the appropriate subclass, all other methods are implemented by the abstractcollection class. If the subclass does not overwrite some methods, an optional method such as add () will throw an exception.

1.2.iterator Interface

The iterator () method of the collection interface returns an iterator. The iterator interface method can access each element in the collection one by one in an iterative manner, and safely remove appropriate elements from the collection.

(1) Boolean hasnext (): determines whether another element is accessible.

Object next (): returns the next element to be accessed. If the collection ends, a nosuchelementexception exception is thrown.

(2) void remove (): deletes the object returned from the last access. This method must be followed by an element. If the set has been modified after the last access, the method will throw illegalstateexception.

"The deletion operation in iterator also affects the underlying collection ."

The iterator is fail-fast. This means that when another thread modifies the underlying set, if you are using iterator to traverse the set, iterator will throw concurrentmodificationexception (another runtimeexception exception) and immediately fail.

2. List Interface

The list interface inherits the collection interface to define an ordered set that allows repeated items. This interface not only processes part of the list, but also adds location-oriented operations.

(1) location-oriented operations include the ability to insert an element or collection, and the ability to obtain, remove, or change an element. You can search for an element in the list from the header or tail of the list. If an element is found, the position of the report element is as follows:

Void add (INT index, object element): Add an element to the index at the specified position.

Boolean addall (INT index, collection C): Adds all elements of set C to the specified position index.

Object get (INT index): returns the elements at the specified position in the list.

Int indexof (Object O): returns the first position where the element o appears. Otherwise,-1 is returned.

Int lastindexof (Object O): returns the position where the last element o appears. Otherwise,-1 is returned.

Object remove (INT index): deletes elements at a specified position.

Object set (INT index, object element): replaces the element on the Position Index with element, and returns the old element.

(2) The list interface not only traverses the entire list by position sequence iteration, but also can process the subset of the Set:

Listiterator (): returns a list iterator used to access elements in the list.

Listiterator (INT index): returns a list iterator used to access the elements in the list from the specified index.

List sublist (INT fromindex, int toindex): returns the list view of each element from the specified position fromindex (included) to the toindex (not included ).

"Changes to sub-lists (such as add (), remove (), and set () calls) also affect the underlying list ."

2.1.listiterator Interface

The listiterator interface inherits the iterator interface to support adding or modifying elements in the underlying set and bidirectional access. The listiterator does not have the current position, and the cursor is located between the values returned by calling the previous and next methods. A list with a length of N with n + 1 valid index value:


(1) void add (Object O): add the object O to the front of the current location

Void set (Object O): replaces object O with the previous element accessed by the next or previous method. If the list structure is modified after the last call, an illegalstateexception is thrown.

(2) Boolean hasprevious (): determines whether there are elements accessible during backward iteration.

Object previous (): returns the previous object

Int nextindex (): returns the index of the element returned when the next method is called.

Int previusindex (): returns the index of the element returned when the previous method is called the next time.

"Normally, you do not need listiterator to change the direction of elements in a traversal set-forward or backward. Although technically feasible, previous () calls next () immediately and returns the same element. The order of calling next () and previous () is reversed and the result is the same ."

"We need to explain the add () operation a little more. Adding an element will immediately add the new element to the front of the implicit cursor. Therefore, calling previous () after adding an element will return a new element, but calling next () will not work. The next element before the add operation will be returned ."

2.2.abstractlist and abstractsequentiallist abstract classes

There are two abstract List Implementation classes: abstractlist and abstractsequentiallist. Like the abstractset class, they overwrite the equals () and hashcode () methods to ensure that two equal sets return the same hash code. If the two lists are of the same size and contain the same elements in the same order, the two lists are the same. The hashcode () Here is specified in the list interface definition, and implemented here.

Except equals () and hashcode (), abstractlist and abstractsequentiallist implement part of the other list methods. Because Random Access to data and sequential access are implemented separately, it is easier to create a specific list. A set of methods to be defined depends on the behavior you want to support. You never have to provide the Implementation of The iterator method in person.

2.3. arrays list class and arraylist class

There are two common list implementations in the "collection framework": arraylist and sorted list. Which of the two lists is implemented depends on your specific needs. To support random access without inserting or removing elements at any position except the tail, arraylist provides an optional set. However, if you want to frequently add and remove elements from the middle of the list, and as long as the elements in the list are accessed sequentially, the sorted list implementation is better.

"Both arraylist and javaslist implement the cloneable interface and provide two constructor functions, one with no parameters and one with another collection"

2.3.1. Sort list class

The List class adds some methods to process elements at both ends of the list.

(1) void addfirst (Object O): Add object O to the beginning of the List

Void addlast (Object O): adds object O to the end of the list.

(2) object getfirst (): returns the element starting with the list.

Object getlast (): returns the element at the end of the list.

(3) object removefirst (): deletes and returns elements starting with the list.

Object removelast (): delete and return the elements at the end of the list.

(4) construct list (): Create an empty list of links

Collections list (collection C): Creates a list of links and Adds all elements of collection C.

"With these new methods, you can easily treat the consumer list as a stack, queue, or other endpoint-oriented data structure ."

2.3.2. arraylist class

The arraylist class encapsulates an array of dynamically distributed objects. Each arraylist object has a capacity. This capacity indicates the capacity of the array that stores the elements in the list. When an element is added to the arraylist, its capacity is automatically increased within the constant time.

In a program that adds a large number of elements to an arraylist object, you can use the ensurecapacity method to increase capacity. This can reduce the number of reallocation increases.

(1) void ensurecapacity (INT mincapacity): increases the arraylist object capacity by mincapacity.

(2) void trimtosize (): the size of the sorted arraylist object is the current size of the list. The program can use this operation to reduce the arraylist object storage space.

2.3.2.1. randomaccess Interface

A feature interface. This interface does not have any method, but you can use this interface to test whether a set supports valid random access. The arraylist and vector classes are used to implement this interface.

3. Set Interface

The Set interface inherits the collection interface and does not allow repeated items in the set. Each specific set implementation class depends on the equals () method of the added object to check uniqueness. The Set interface does not introduce new methods, so set is a collection, but its behavior is different.

3.1. Hash table

A hash table is a data structure used to find objects. The hash table calculates an integer for each object, which is called a hash code ). A hash table is an array of link lists. Each list is called a buckets (hash table element ). Index = hashcode % buckets (hashcode is the object hash code, and buckets is the total number of hash table elements ).

When you add an element, you may encounter a hash table element that has been filled with the element. This is called hash collisions (hash conflict ). In this case, you must determine whether the element already exists in the hash table.

If the hash code is reasonably randomly distributed and the number of hash table elements is large enough, the number of hash conflicts will be reduced. At the same time, you can set an initial number of hash table elements to better control the operation of the hashtable. The initial number of hash table elements is buckets = size * 150% + 1 (size is the expected number of elements ).

If the elements in the hash table are too full, rehashing must be performed ). Hash the number of elements in the hash table is multiplied, and the original object is re-imported into the new hash table element, while the original hash table element is deleted. Load Factor determines when to re-hash the hash table. In Java programming language, the default value of the load factor is 0.75, and the default hash table element is 101.

3.2. Comparable interface and comparator Interface

There are two comparison interfaces in the "set framework": the comparable interface and the comparator interface. Java built-in classes such as string and integer implement the comparable interface to provide certain sorting methods, but this method can only be implemented once. For classes that do not implement the comparable interface or custom classes, you can use the comparator interface to define your own comparison methods.

3.2.1. Comparable Interface

In the java. lang Package, the comparable interface is applicable when a class has a natural order. Assuming that the object set is of the same type, this interface allows you to sort the set in a natural order.

(1) int compareto (Object O): compares the current instance object with the object O. If it is before the object O, a negative value is returned. If the two objects are in the same position in the sorting, 0 is returned, if it is behind object O, a positive value is returned.

In Java 2 SDK 1.4, there are twenty-four classes that implement the comparable interface. The following table shows the natural sorting of eight basic types. Although some classes share the same natural sorting, only comparable classes can be sorted.

Class Sort
Bigdecimal, biginteger, byte, double, float, integer, long, short Sort by number
Character Sort by numbers of Unicode values
String Sort by Unicode values in strings

Using the comparable interface to create the sorting order of your own classes is only a problem of implementing the compareto () method. It usually depends on the natural sorting of several data members. Classes should also overwrite equals () and hashcode () to ensure that two equal objects return the same hash code.

3.2.2. comparator Interface

If a class cannot be used to implement Java. lang. comparable, or you do not like the default comparable behavior and want to provide your own sorting order (there may be multiple sorting methods), you can implement the comparator interface to define a comparator.

(1) int compare (Object O1, object O2): Compares two objects O1 and O2. If O1 is located before O2, a negative value is returned, if O1 and O2 are the same in the sorting order, 0 is returned. If O1 is behind O2, a positive value is returned.

"Similar to comparable, 0 returned values do not indicate equal elements. A return value of 0 indicates that two objects are in the same position. The comparator user determines how to handle the problem. If the result of comparing two unequal elements is zero, you should first make sure that it is the result you want and then record the behavior ."

(2) Boolean equals (Object OBJ): indicates whether the object obj is equal to the comparator.

"This method overwrites the equals () method of the object. It checks the equality implemented by comparator, not the object in the comparison state ."

3.3. sortedset Interface

The "collection framework" provides a special set interface: sortedset, which maintains the orderly order of elements. The sortedset interface provides access methods for the view (subset) of a set and its two ends (header and tail. When you process the subset of the list, changing the view will be reflected in the source set. In addition, changes to the source set are also reflected in the subset. The reason for this is that the view is specified by the element at both ends rather than the subscript element. Therefore, if you want a special high-end element in the subset, you must find the next element.

The elements added to the sortedset implementation class must implement the comparable interface. Otherwise, you must provide a comparator interface for its constructor. The treeset class is its only implementation.

"Because the set must contain a unique item, if two elements are compared when an element is added, the return value is 0 (through the compareto () method of comparable or comparator's compare () method ), then the new element is not added. If the two elements are equal, it's okay. However, if they are not equal, you should modify the comparison method to make the comparison method and equals () have the same effect ."

(1) comparator (): returns the comparator used to sort elements. If the compareto () method of the comparable interface is used to compare elements, null is returned.

(2) object first (): returns the first (lowest) element in the sorted set.

(3) Object last (): returns the last (highest) element in the sorted set.

(4) sortedset subset (Object fromelement, object toelement): return the sortedset view (subset) of elements in the range from fromelement (included) to toelement (excluded)

(5) sortedset headset (Object toelement): return a view of sortedset, with each element smaller than toelement.

(6) sortedset tailset (Object fromelement): returns a view of sortedset, with each element greater than or equal to fromelement.

3.4. abstractset abstract class

The abstractset class overwrites the equals () and hashcode () Methods of the object class to ensure that two equal sets return the same hash code. If the two sets are equal in size and contain the same elements, the two sets are equal. By definition, the hash code of a set is the sum of hash codes of elements in a set. Therefore, two equal sets have the same hash code regardless of the internal sequence of the set.

3.4.1. Object Class

(1) Boolean equals (Object OBJ): Compares two objects to determine whether they are the same

(2) int hashcode (): return the hash code of the object. The same hash code must be returned for the same object.

3.5. hashset class and treeset class

The set framework supports two common implementations: hashset and treeset (the sortedset interface implemented by treeset ). In more cases, you will use hashset to store repeated free sets. Considering the efficiency, the hashcode () method must be implemented for the objects added to the hashset by appropriately allocating hash codes. Although most system classes cover the default Implementation of hashcode () and equals () in the object, do not forget to overwrite hashcode () and equals () when creating your own classes to be added to the hashset ().

The treeset implementation is useful when you want to insert and extract elements in an ordered manner from a set. In order to proceed smoothly, the elements added to the treeset must be sorted.

3.5.1.hashset class

(1) hashset (): Construct an empty hash set.

(2) hashset (collection C): Creates a hash set and Adds all elements in set C.

(3) hashset (INT initialcapacity): Construct an empty hash set with specific capacity.

(4) hashset (INT initialcapacity, float loadfactor): Construct an empty hash set with a specific capacity and load factor. Loadfactor is a number between 0.0 and 1.0.

3.5.2. treeset class

(1) treeset (): Construct an empty tree set.

(2) treeset (collection C): Build a tree set and add all elements in set C.

(3) treeset (comparator C): constructs a tree set and sorts its elements using a specific comparator.

"The comparator does not have any data. It is just a comparison tool. This type of object is sometimes called a function object. Function objects are usually defined as an instance of an anonymous internal class during running ."

Treeset (sortedset S): Construct a tree set, add all elements in the ordered set S, and sort by the same comparator as the ordered set S.

3.6. linkedhashset class

Linkedhashset extends the hashset. If you want to track the sequence of elements added to a hashset, The linkedhashset implementation will be helpful. The iterator of linkedhashset accesses each element according to the element insertion sequence. It provides an ordered set of elements that can be quickly accessed. At the same time, it also increases the implementation cost, because each element in the hash table element is linked together through a dual-link list.

(1) construct hashset (): Construct an empty link hash set.

(2) linkedhashset (collection C): constructs a link-based hash set and Adds all elements in set C.

(3) construct hashset (INT initialcapacity): Construct an empty link hash set with specific capacity.

(4) construct hashset (INT initialcapacity, float loadfactor): Construct an empty link hash set with a specific capacity and load factor. Loadfactor is a number between 0.0 and 1.0.

"To optimize the use of the hashset space, you can optimize the initial capacity and load factor. Treeset does not contain optimization options because the tree is always balanced ."

4. Map Interface

The map interface is not inherited from the collection interface. The map interface is used to maintain key/value pairs (key/value pairs ). This interface describes the ing from duplicate keys to values.

(1) add and delete operations:

Object put (Object key, object Value): put a key and value associated with each other into the image. If this keyword already exists, the new value associated with this keyword will replace the old value. Method returns the old value of the keyword. If the keyword does not exist, null is returned.

Object remove (Object key): deletes key-related mappings from the image.

Void putall (map t): Adds all elements from a specific image to the image.

Void clear (): deletes all mappings from the image.

"Keys and values can both be null. However, you cannot add map as a key or value to yourself ."

(2) query operations:

Object get (Object key): obtains the value related to the keyword key and returns the object related to the keyword key. If this keyword is not found in the image, null is returned.

Boolean containskey (Object key): determines whether a keyword key exists in the image.

Boolean containsvalue (object Value): determines whether a value exists in the image.

Int size (): returns the number of mappings in the current image.

Boolean isempty (): determines whether any ing exists in the image.

(3) view operation: process the Middle-key/value pairs in the image.

Set keyset (): returns the gallery of all keywords in the image.

"Because the set in the ing key must be unique, you can use set to support it. You can also delete an element from the view. At the same time, the value related to the keyword will be deleted from the source image, but you cannot add any element ."

Collection values (): returns the gallery of all values in the image.

"Because the set of ing values is not unique, you can use collection to support it. You can also delete an element from the view. At the same time, the value and its keyword will be deleted from the source image, but you cannot add any element ."

Set entryset (): returns the gallery of map. entry objects, that is, the keyword/value pair in the image.

"Because the ing is unique, you can use set to support it. You can also delete elements from the view. At the same time, these elements will be deleted from the source image, but you cannot add any elements ."

4.1. Map. Entry interface

The entryset () method of map returns a set of objects that implement the map. entry interface. Each object in the set is a specific key/value pair in the underlying map.

Through the iterator of this set, you can obtain the key or value of each entry (unique acquisition method) and change the value. After an entry is returned through the iterator, unless it is the iterator's own remove () method or the setvalue () method of the entry returned by the iterator, other modifications to the source map will invalidate the entry set, and the entry behavior will be undefined.

(1) object getkey (): return the keyword of the Entry

(2) object getvalue (): return the value of the Entry

(3) object setvalue (object Value): change the value in the relevant image to value and return the old value.

4.2. sortedmap Interface

The Collection framework provides a special map interface: sortedmap, which is used to maintain the orderly order of keys.

The sortedmap interface is the image view (subset), including two endpoints that provide access methods. Except for sorting keys acting on mappings, sortedmap processing is the same as sortedset processing.

The elements added to the sortedmap implementation class must implement the comparable interface. Otherwise, you must provide a comparator interface for its constructor. The treemap class is its only implementation.

"Because for ing, each key can correspond to only one value. If two keys are compared when a key/value pair is added, the return value is 0 (through compareto () of comparable () method or through comparator's compare () method), then the corresponding value of the original key is replaced by a new value. If the two elements are equal, it's okay. However, if they are not equal, you should modify the comparison method so that the comparison method and equals () have the same effect ."

(1) comparator (): returns the comparator used to sort keywords. If the compareto () method of the comparable interface is used to compare keywords, null is returned.

(2) object firstkey (): returns the first (lowest) keyword in the image.

(3) object lastkey (): returns the last (highest) keyword in the image.

(4) sortedmap submap (Object fromkey, object Tokey): return the sortedmap view (subset) of elements in the range from fromkey (included) to Tokey (excluded)

(5) sortedmap headmap (Object Tokey): return a view of sortedmap, where the keys of each element are smaller than Tokey.

(6) sortedset tailmap (Object fromkey): return a view of sortedmap, where the keys of each element are greater than or equal to fromkey.

4.3. abstractmap abstract class

Similar to other abstract sets, the abstractmap class overwrites the equals () and hashcode () methods to ensure that two equal mappings return the same hash code. If the two mappings are of the same size, contain the same key, and each key has the same value in both mappings, the two mappings are equal. The mapped hash code is the sum of the mapped element hash codes. Each element is an implementation of the map. entry interface. Therefore, two equal mappings report the same hash code regardless of the internal order of the ing.

4.4. hashmap class and treemap class

The Collection framework provides two general map implementations: hashmap and treemap (the sortedmap interface implemented by treemap ). Hashmap is the best choice for inserting, deleting, and locating elements in a map. However, if you want to traverse keys in the natural or custom order, it is better to use treemap. The key classes required to be added using hashmap clearly define the implementation of hashcode () and equals.

This treemap has no optimization options because the tree is always in the balance state.

4.4.1. hashmap class

To optimize the use of the hashmap space, you can optimize the initial capacity and load factor.

(1) hashmap (): Construct an empty hash image.

(2) hashmap (MAP m): Build a hash image and add all Mappings of the image M.

(3) hashmap (INT initialcapacity): creates an empty hash image with a specific capacity.

(4) hashmap (INT initialcapacity, float loadfactor): Build an empty hash image with a specific capacity and loading Factor

4.4.2. treemap class

Treemap has no optimization option because the tree is always in the balance state.

(1) treemap (): Construct an empty image tree

(2) treemap (MAP m): build an image tree and add all elements in image M.

(3) treemap (comparator C): build an image tree and use a specific comparator to sort keywords.

(4) treemap (sortedmap S): build an image tree, add all mappings in the image tree S, and sort by the same comparator as the ordered image S.

4.5. linkedhashmap class

Linkedhashmap extends hashmap and adds key/value pairs to the link hash image in the insertion order. Like linkedhashset, linkedhashmap uses a dual-link list.

(1) construct hashmap (): Construct an empty link hash image.

(2) linkedhashmap (MAP m): Build a link hash image and add all mappings in image M.

(3) linkedhashmap (INT initialcapacity): creates an empty link hash image with a specific capacity.

(4) linkedhashmap (INT initialcapacity, float loadfactor): Build an empty link hash image with a specific capacity and load factor.

(5) linkedhashmap (INT initialcapacity, float loadfactor,

Boolean accessorder): creates an empty link hash image with a specific capacity, load factor, and access sequence.

"If you set accessorder to true, the link hash image uses the access sequence instead of the insertion sequence to overlap.

For each image. Each time you call the get or put method, the corresponding ing is deleted from its current location, put it at the end of the linked image list (only the locations in the linked image list are affected, and the hash table elements are not affected. Hash Table ing is always waiting in the hash table corresponding to the hash code of the keyword )."

"This feature is useful for implementing the" delete least recently used "principle of high-speed cache. For example, you can save the most frequently accessed mappings in the memory and read infrequently accessed objects from the database. When you cannot find a ing in the table and the ing in the table is fully filled, you can let the iterator enter the table and delete the mappings at the beginning of its enumeration. These are the least recently used mappings ."

(6) protected Boolean removeeldestentry (Map. Entry eldest): If you want to delete the oldest ing, override this method to return true. This method is called after a ing has been added to the image. Its default implementation method returns false, indicating that the old ing is not deleted by default. However, you can redefine this method to selectively return true if the oldest ing meets a certain condition or the image exceeds a certain size.

4.6. weakhashmap class

Weakhashmap is a special implementation of map. It uses weakreference (weak reference) to store hash table keywords. In this way, when the ing key is no longer referenced outside weakhashmap, the garbage collector recycles it, but it will include the weak references that reach this object into a queue. Running weakhashmap regularly checks the queue to identify new weak applications. When a weak reference reaches the queue, it indicates that the keyword is no longer used by anyone and has been collected. Then weakhashmap deletes the corresponding ing.

(1) weakhashmap (): Construct an empty weak hash image.

(2) weakhashmap (map t): Creates a weak hash image and Adds all mappings in image T.

(3) weakhashmap (INT initialcapacity): Construct a weak hash image with null values of specific capacity.

(4) weakhashmap (INT initialcapacity, float loadfactor): Build a weak hash image with null values of specific capacity and loading factor.

4.6. identityhashmap class

Identityhashmap is also a special implementation of map. In this class, the hash code of a keyword should not be calculated by the hashcode () method, but by the system. identityhashcode method (even if the hashcode method has been redefined ). This is the method used by object. hashcode to calculate the hash code based on the object's memory address. To compare objects, identityhashmap uses = instead of the equals method.

In other words, different keyword objects are considered as different objects even if their content is the same. The identityhashmap class can be used to convert the topology of an object (such as serializing or copying objects in depth, A "Node table" is required to track the references of objects that have been processed. Even if an object happens to be equal, the "Node table" should not be considered equal. Another application is the maintenance proxy object. For example, the debugging tool wants to maintain a proxy object for each object during program debugging.

"The identityhashmap class is not a map implementation in general sense! Its implementation intentionally violates the Convention that the map interface requires comparing objects through the equals method. This class is used only when equality semantics is rarely emphasized ."

(1) identityhashmap (): creates an empty all-identical hash image. The default maximum size is 21.

"The expected maximum size is the maximum number of key/value ing that the image expects to hold"

(2) identityhashmap (MAP m): Creates a fully identical hash image and Adds all mappings in image M.

(3) identityhashmap (INT expectedmaxsize): creates an empty hash image with the expected maximum size. When you place a key/value ing that exceeds the expected maximum size, the internal data structure may increase, sometimes time consuming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.