The Hash Set Class Java Help

The Hash Set Class
Hash Set extends Abstract Set and implements the Set interface. It creates a collection the uses a hash table for storage. As most readers likely know, a hash table information by using a mechanism called hashing. In hashing, the informational content of a keyis used to determine a unique value, called its hash code. The hash code is then used as the index at which the data associated with the key is stored, The transformation of the key into its hash code is performed automatically=-you never see the hash code itself. Also, your code can’t directly index the hash table .•The advantage of hashing is that it allows the execution time of basic operations, such as add( ), containst ), remover ), and sizet }, to remain constant even for large sets. The following constructors are defined:
Hash Set( )
Hash Set(Collection c)
Hash Set(int capacity) /
Hash Set(int capacitor}, float fil/Ratio)
The first form constructs a deftult hash set. The second form initializes the hash set by using the elements of c. The third form initializes the capacity of the hash set to capilcity. TIle fourth form initializes both the capacity and the fill ratio (also called load pllcity) of the hash set from its arguments. The fill ratio must be between  and 1.0, and it determines how full the hash set can be before it is rcsizcd upward. Specifically, when the number of clements is greater than the capacity of the hash set multiplied by its fill ratio, the hash set is expanded. For constructors that do not take a fill ratio, 0.75 is used. Hash Set does not define any additional methods beyond those provided by its superclasses and interfaces. . Importantly, note that a hash set does not guarantee the order of its Clements because the process of hashing doesn’t usually lend itself to the creation of sorted sets, If you need sorted storage, then another collection, such IS Trc cOst, is a better choice. Here is an example that demonstrates Hash’Set: The following is the output from this program:

[F, E, D, C, B, AJ
As explained, the elements are not stored in sorted order.

  • Feel free to send us an inquiry, we will reply back in hours.


Posted on September 17, 2014 in java util Part 1 The Collections Framework

Share the Story

About the Author

Back to Top