Hashtable Class (System.Collections) (2024)

  • Reference

Definition

Namespace:
System.Collections
Assemblies:
mscorlib.dll, System.Collections.NonGeneric.dll
Assembly:
System.Runtime.dll
Assembly:
System.Collections.NonGeneric.dll
Assembly:
System.Runtime.Extensions.dll
Assembly:
mscorlib.dll
Assembly:
netstandard.dll
Source:
Hashtable.cs
Source:
Hashtable.cs
Source:
Hashtable.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Represents a collection of key/value pairs that are organized based on the hash code of the key.

public ref class Hashtable : System::Collections::IDictionary
public ref class Hashtable : ICloneable, System::Collections::IDictionary, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public class Hashtable : System.Collections.IDictionary
public class Hashtable : ICloneable, System.Collections.IDictionary, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Serializable]public class Hashtable : ICloneable, System.Collections.IDictionary, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Serializable][System.Runtime.InteropServices.ComVisible(true)]public class Hashtable : ICloneable, System.Collections.IDictionary, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
type Hashtable = class interface ICollection interface IEnumerable interface IDictionary
type Hashtable = class interface ICollection interface IEnumerable interface IDictionary interface ICloneable interface IDeserializationCallback interface ISerializable
type Hashtable = class interface ICollection interface IEnumerable interface IDictionary interface ISerializable interface IDeserializationCallback interface ICloneable
[<System.Serializable>]type Hashtable = class interface IDictionary interface ICollection interface IEnumerable interface ISerializable interface IDeserializationCallback interface ICloneable
[<System.Serializable>][<System.Runtime.InteropServices.ComVisible(true)>]type Hashtable = class interface IDictionary interface ICollection interface IEnumerable interface ISerializable interface IDeserializationCallback interface ICloneable
Public Class HashtableImplements IDictionary
Public Class HashtableImplements ICloneable, IDeserializationCallback, IDictionary, ISerializable
Inheritance
Derived

System.Configuration.SettingsAttributeDictionary

System.Configuration.SettingsContext

System.Data.PropertyCollection

System.Printing.IndexedProperties.PrintPropertyDictionary

Attributes

SerializableAttributeComVisibleAttribute

Implements

ICollectionIDictionaryIEnumerableICloneableIDeserializationCallbackISerializable

Examples

The following example shows how to create, initialize and perform various functions to a Hashtable and how to print out its keys and values.

using namespace System;using namespace System::Collections;public ref class Example{public: static void Main() { // Create a new hash table. // Hashtable^ openWith = gcnew Hashtable(); // Add some elements to the hash table. There are no // duplicate keys, but some of the values are duplicates. openWith->Add("txt", "notepad.exe"); openWith->Add("bmp", "paint.exe"); openWith->Add("dib", "paint.exe"); openWith->Add("rtf", "wordpad.exe"); // The Add method throws an exception if the new key is // already in the hash table. try { openWith->Add("txt", "winword.exe"); } catch(...) { Console::WriteLine("An element with Key = \"txt\" already exists."); } // The Item property is the default property, so you // can omit its name when accessing elements. Console::WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]); // The default Item property can be used to change the value // associated with a key. openWith["rtf"] = "winword.exe"; Console::WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]); // If a key does not exist, setting the default Item property // for that key adds a new key/value pair. openWith["doc"] = "winword.exe"; // ContainsKey can be used to test keys before inserting // them. if (!openWith->ContainsKey("ht")) { openWith->Add("ht", "hypertrm.exe"); Console::WriteLine("Value added for key = \"ht\": {0}", openWith["ht"]); } // When you use foreach to enumerate hash table elements, // the elements are retrieved as KeyValuePair objects. Console::WriteLine(); for each( DictionaryEntry de in openWith ) { Console::WriteLine("Key = {0}, Value = {1}", de.Key, de.Value); } // To get the values alone, use the Values property. ICollection^ valueColl = openWith->Values; // The elements of the ValueCollection are strongly typed // with the type that was specified for hash table values. Console::WriteLine(); for each( String^ s in valueColl ) { Console::WriteLine("Value = {0}", s); } // To get the keys alone, use the Keys property. ICollection^ keyColl = openWith->Keys; // The elements of the KeyCollection are strongly typed // with the type that was specified for hash table keys. Console::WriteLine(); for each( String^ s in keyColl ) { Console::WriteLine("Key = {0}", s); } // Use the Remove method to remove a key/value pair. Console::WriteLine("\nRemove(\"doc\")"); openWith->Remove("doc"); if (!openWith->ContainsKey("doc")) { Console::WriteLine("Key \"doc\" is not found."); } }};int main(){ Example::Main();}/* This code example produces the following output:An element with Key = "txt" already exists.For key = "rtf", value = wordpad.exe.For key = "rtf", value = winword.exe.Value added for key = "ht": hypertrm.exeKey = dib, Value = paint.exeKey = txt, Value = notepad.exeKey = ht, Value = hypertrm.exeKey = bmp, Value = paint.exeKey = rtf, Value = winword.exeKey = doc, Value = winword.exeValue = paint.exeValue = notepad.exeValue = hypertrm.exeValue = paint.exeValue = winword.exeValue = winword.exeKey = dibKey = txtKey = htKey = bmpKey = rtfKey = docRemove("doc")Key "doc" is not found. */
using System;using System.Collections;class Example{ public static void Main() { // Create a new hash table. // Hashtable openWith = new Hashtable(); // Add some elements to the hash table. There are no // duplicate keys, but some of the values are duplicates. openWith.Add("txt", "notepad.exe"); openWith.Add("bmp", "paint.exe"); openWith.Add("dib", "paint.exe"); openWith.Add("rtf", "wordpad.exe"); // The Add method throws an exception if the new key is // already in the hash table. try { openWith.Add("txt", "winword.exe"); } catch { Console.WriteLine("An element with Key = \"txt\" already exists."); } // The Item property is the default property, so you // can omit its name when accessing elements. Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]); // The default Item property can be used to change the value // associated with a key. openWith["rtf"] = "winword.exe"; Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]); // If a key does not exist, setting the default Item property // for that key adds a new key/value pair. openWith["doc"] = "winword.exe"; // ContainsKey can be used to test keys before inserting // them. if (!openWith.ContainsKey("ht")) { openWith.Add("ht", "hypertrm.exe"); Console.WriteLine("Value added for key = \"ht\": {0}", openWith["ht"]); } // When you use foreach to enumerate hash table elements, // the elements are retrieved as KeyValuePair objects. Console.WriteLine(); foreach( DictionaryEntry de in openWith ) { Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value); } // To get the values alone, use the Values property. ICollection valueColl = openWith.Values; // The elements of the ValueCollection are strongly typed // with the type that was specified for hash table values. Console.WriteLine(); foreach( string s in valueColl ) { Console.WriteLine("Value = {0}", s); } // To get the keys alone, use the Keys property. ICollection keyColl = openWith.Keys; // The elements of the KeyCollection are strongly typed // with the type that was specified for hash table keys. Console.WriteLine(); foreach( string s in keyColl ) { Console.WriteLine("Key = {0}", s); } // Use the Remove method to remove a key/value pair. Console.WriteLine("\nRemove(\"doc\")"); openWith.Remove("doc"); if (!openWith.ContainsKey("doc")) { Console.WriteLine("Key \"doc\" is not found."); } }}/* This code example produces the following output:An element with Key = "txt" already exists.For key = "rtf", value = wordpad.exe.For key = "rtf", value = winword.exe.Value added for key = "ht": hypertrm.exeKey = dib, Value = paint.exeKey = txt, Value = notepad.exeKey = ht, Value = hypertrm.exeKey = bmp, Value = paint.exeKey = rtf, Value = winword.exeKey = doc, Value = winword.exeValue = paint.exeValue = notepad.exeValue = hypertrm.exeValue = paint.exeValue = winword.exeValue = winword.exeKey = dibKey = txtKey = htKey = bmpKey = rtfKey = docRemove("doc")Key "doc" is not found. */
Imports System.CollectionsModule Example Sub Main() ' Create a new hash table. ' Dim openWith As New Hashtable() ' Add some elements to the hash table. There are no ' duplicate keys, but some of the values are duplicates. openWith.Add("txt", "notepad.exe") openWith.Add("bmp", "paint.exe") openWith.Add("dib", "paint.exe") openWith.Add("rtf", "wordpad.exe") ' The Add method throws an exception if the new key is ' already in the hash table. Try openWith.Add("txt", "winword.exe") Catch Console.WriteLine("An element with Key = ""txt"" already exists.") End Try ' The Item property is the default property, so you ' can omit its name when accessing elements. Console.WriteLine("For key = ""rtf"", value = {0}.", _ openWith("rtf")) ' The default Item property can be used to change the value ' associated with a key. openWith("rtf") = "winword.exe" Console.WriteLine("For key = ""rtf"", value = {0}.", _ openWith("rtf")) ' If a key does not exist, setting the default Item property ' for that key adds a new key/value pair. openWith("doc") = "winword.exe" ' ContainsKey can be used to test keys before inserting ' them. If Not openWith.ContainsKey("ht") Then openWith.Add("ht", "hypertrm.exe") Console.WriteLine("Value added for key = ""ht"": {0}", _ openWith("ht")) End If ' When you use foreach to enumerate hash table elements, ' the elements are retrieved as KeyValuePair objects. Console.WriteLine() For Each de As DictionaryEntry In openWith Console.WriteLine("Key = {0}, Value = {1}", _ de.Key, de.Value) Next de ' To get the values alone, use the Values property. Dim valueColl As ICollection = openWith.Values ' The elements of the ValueCollection are strongly typed ' with the type that was specified for hash table values. Console.WriteLine() For Each s As String In valueColl Console.WriteLine("Value = {0}", s) Next s ' To get the keys alone, use the Keys property. Dim keyColl As ICollection = openWith.Keys ' The elements of the KeyCollection are strongly typed ' with the type that was specified for hash table keys. Console.WriteLine() For Each s As String In keyColl Console.WriteLine("Key = {0}", s) Next s ' Use the Remove method to remove a key/value pair. Console.WriteLine(vbLf + "Remove(""doc"")") openWith.Remove("doc") If Not openWith.ContainsKey("doc") Then Console.WriteLine("Key ""doc"" is not found.") End If End SubEnd Module' This code example produces the following output:''An element with Key = "txt" already exists.'For key = "rtf", value = wordpad.exe.'For key = "rtf", value = winword.exe.'Value added for key = "ht": hypertrm.exe''Key = dib, Value = paint.exe'Key = txt, Value = notepad.exe'Key = ht, Value = hypertrm.exe'Key = bmp, Value = paint.exe'Key = rtf, Value = winword.exe'Key = doc, Value = winword.exe''Value = paint.exe'Value = notepad.exe'Value = hypertrm.exe'Value = paint.exe'Value = winword.exe'Value = winword.exe''Key = dib'Key = txt'Key = ht'Key = bmp'Key = rtf'Key = doc''Remove("doc")'Key "doc" is not found.
# Create new hash table using PowerShell syntax.$OpenWith = @{}# Add one element to the hash table using the Add method.$OpenWith.Add('txt', 'notepad.exe')# Add three elements using PowerShell syntax three different ways.$OpenWith.dib = 'paint.exe'$KeyBMP = 'bmp'$OpenWith[$KeyBMP] = 'paint.exe'$OpenWith += @{'rtf' = 'wordpad.exe'}# Display hash table."There are {0} in the `$OpenWith hash table as follows:" -f $OpenWith.Count''# Display hashtable properties.'Count of items in the hashtable : {0}' -f $OpenWith.Count'Is hashtable fixed size? : {0}' -f $OpenWith.IsFixedSize'Is hashtable read-only? : {0}' -f $OpenWith.IsReadonly'Is hashtable synchronised? : {0}' -f $OpenWith.IsSynchronized'''Keys in hashtable:'$OpenWith.Keys'''Values in hashtable:'$OpenWith.Values''<#This script produces the following output:There are 4 in the $OpenWith hash table as follows:Name Value---- -----txt notepad.exedib paint.exebmp paint.exertf wordpad.exeCount of items in the hashtable : 4Is hashtable fixed size? : FalseIs hashtable read-only? : FalseIs hashtable synchronised? : FalseKeys in hashtable:txtdibbmprtfValues in hashtable:notepad.exepaint.exepaint.exewordpad.exe#>

Remarks

Each element is a key/value pair stored in a DictionaryEntry object. A key cannot be null, but a value can be.

Important

We don't recommend that you use the Hashtable class for new development. Instead, we recommend that you use the generic Dictionary<TKey,TValue> class. For more information, see Non-generic collections shouldn't be used on GitHub.

The objects used as keys by a Hashtable are required to override the Object.GetHashCode method (or the IHashCodeProvider interface) and the Object.Equals method (or the IComparer interface). The implementation of both methods and interfaces must handle case sensitivity the same way; otherwise, the Hashtable might behave incorrectly. For example, when creating a Hashtable, you must use the CaseInsensitiveHashCodeProvider class (or any case-insensitive IHashCodeProvider implementation) with the CaseInsensitiveComparer class (or any case-insensitive IComparer implementation).

Furthermore, these methods must produce the same results when called with the same parameters while the key exists in the Hashtable. An alternative is to use a Hashtable constructor with an IEqualityComparer parameter. If key equality were simply reference equality, the inherited implementation of Object.GetHashCode and Object.Equals would suffice.

Key objects must be immutable as long as they are used as keys in the Hashtable.

When an element is added to the Hashtable, the element is placed into a bucket based on the hash code of the key. Subsequent lookups of the key use the hash code of the key to search in only one particular bucket, thus substantially reducing the number of key comparisons required to find an element.

The load factor of a Hashtable determines the maximum ratio of elements to buckets. Smaller load factors cause faster average lookup times at the cost of increased memory consumption. The default load factor of 1.0 generally provides the best balance between speed and size. A different load factor can also be specified when the Hashtable is created.

As elements are added to a Hashtable, the actual load factor of the Hashtable increases. When the actual load factor reaches the specified load factor, the number of buckets in the Hashtable is automatically increased to the smallest prime number that is larger than twice the current number of Hashtable buckets.

Each key object in the Hashtable must provide its own hash function, which can be accessed by calling GetHash. However, any object implementing IHashCodeProvider can be passed to a Hashtable constructor, and that hash function is used for all objects in the table.

The capacity of a Hashtable is the number of elements the Hashtable can hold. As elements are added to a Hashtable, the capacity is automatically increased as required through reallocation.

.NET Framework only: For very large Hashtable objects, you can increase the maximum capacity to 2 billion elements on a 64-bit system by setting the enabled attribute of the <gcAllowVeryLargeObjects> configuration element to true in the run-time environment.

The foreach statement of the C# language (For Each in Visual Basic) returns an object of the type of the elements in the collection. Since each element of the Hashtable is a key/value pair, the element type is not the type of the key or the type of the value. Instead, the element type is DictionaryEntry. For example:

for each(DictionaryEntry de in myHashtable){ // ...}
foreach(DictionaryEntry de in myHashtable){ // ...}
For Each de As DictionaryEntry In myHashtable ' ...Next de

The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.

Because serializing and deserializing an enumerator for a Hashtable can cause the elements to become reordered, it is not possible to continue enumeration without calling the Reset method.

Note

Because keys can be inherited and their behavior changed, their absolute uniqueness cannot be guaranteed by comparisons using the Equals method.

Constructors

Hashtable()

Initializes a new, empty instance of the Hashtable class using the default initial capacity, load factor, hash code provider, and comparer.

Hashtable(IDictionary, IEqualityComparer)

Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to a new Hashtable object. The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the default load factor and the specified IEqualityComparer object.

Hashtable(IDictionary, IHashCodeProvider, IComparer)

Obsolete.

Obsolete.

Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the default load factor, and the specified hash code provider and comparer. This API is obsolete. For an alternative, see Hashtable(IDictionary, IEqualityComparer).

Hashtable(IDictionary, Single, IEqualityComparer)

Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the specified load factor and IEqualityComparer object.

Hashtable(IDictionary, Single, IHashCodeProvider, IComparer)

Obsolete.

Obsolete.

Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the specified load factor, hash code provider, and comparer.

Hashtable(IDictionary, Single)

Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the specified load factor, and the default hash code provider and comparer.

Hashtable(IDictionary)

Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the default load factor, hash code provider, and comparer.

Hashtable(IEqualityComparer)

Initializes a new, empty instance of the Hashtable class using the default initial capacity and load factor, and the specified IEqualityComparer object.

Hashtable(IHashCodeProvider, IComparer)

Obsolete.

Obsolete.

Obsolete.

Initializes a new, empty instance of the Hashtable class using the default initial capacity and load factor, and the specified hash code provider and comparer.

Hashtable(Int32, IEqualityComparer)

Initializes a new, empty instance of the Hashtable class using the specified initial capacity and IEqualityComparer, and the default load factor.

Hashtable(Int32, IHashCodeProvider, IComparer)

Obsolete.

Obsolete.

Initializes a new, empty instance of the Hashtable class using the specified initial capacity, hash code provider, comparer, and the default load factor.

Hashtable(Int32, Single, IEqualityComparer)

Initializes a new, empty instance of the Hashtable class using the specified initial capacity, load factor, and IEqualityComparer object.

Hashtable(Int32, Single, IHashCodeProvider, IComparer)

Obsolete.

Obsolete.

Initializes a new, empty instance of the Hashtable class using the specified initial capacity, load factor, hash code provider, and comparer.

Hashtable(Int32, Single)

Initializes a new, empty instance of the Hashtable class using the specified initial capacity and load factor, and the default hash code provider and comparer.

Hashtable(Int32)

Initializes a new, empty instance of the Hashtable class using the specified initial capacity, and the default load factor, hash code provider, and comparer.

Hashtable(SerializationInfo, StreamingContext)

Obsolete.

Initializes a new, empty instance of the Hashtable class that is serializable using the specified SerializationInfo and StreamingContext objects.

Properties

comparer

Obsolete.

Obsolete.

Gets or sets the IComparer to use for the Hashtable.

Count

Gets the number of key/value pairs contained in the Hashtable.

EqualityComparer

Gets the IEqualityComparer to use for the Hashtable.

hcp

Obsolete.

Obsolete.

Gets or sets the object that can dispense hash codes.

IsFixedSize

Gets a value indicating whether the Hashtable has a fixed size.

IsReadOnly

Gets a value indicating whether the Hashtable is read-only.

IsSynchronized

Gets a value indicating whether access to the Hashtable is synchronized (thread safe).

Item[Object]

Gets or sets the value associated with the specified key.

Keys

Gets an ICollection containing the keys in the Hashtable.

SyncRoot

Gets an object that can be used to synchronize access to the Hashtable.

Values

Gets an ICollection containing the values in the Hashtable.

Methods

Add(Object, Object)

Adds an element with the specified key and value into the Hashtable.

Clear()

Removes all elements from the Hashtable.

Clone()

Creates a shallow copy of the Hashtable.

Contains(Object)

Determines whether the Hashtable contains a specific key.

ContainsKey(Object)

Determines whether the Hashtable contains a specific key.

ContainsValue(Object)

Determines whether the Hashtable contains a specific value.

CopyTo(Array, Int32)

Copies the Hashtable elements to a one-dimensional Array instance at the specified index.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator()

Returns an IDictionaryEnumerator that iterates through the Hashtable.

GetHash(Object)

Returns the hash code for the specified key.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext)

Obsolete.

Implements the ISerializable interface and returns the data needed to serialize the Hashtable.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
KeyEquals(Object, Object)

Compares a specific Object with a specific key in the Hashtable.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnDeserialization(Object)

Implements the ISerializable interface and raises the deserialization event when the deserialization is complete.

Remove(Object)

Removes the element with the specified key from the Hashtable.

Synchronized(Hashtable)

Returns a synchronized (thread-safe) wrapper for the Hashtable.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

Thread Safety

Hashtable is thread safe for use by multiple reader threads and a single writing thread. It is thread safe for multi-thread use when only one of the threads perform write (update) operations, which allows for lock-free reads provided that the writers are serialized to the Hashtable. To support multiple writers all operations on the Hashtable must be done through the wrapper returned by the Synchronized(Hashtable) method, provided that there are no threads reading the Hashtable object.

Enumerating through a collection is intrinsically not a thread safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

See also

  • IDictionary
  • IHashCodeProvider
  • GetHashCode()
  • Equals(Object)
  • DictionaryEntry
  • Dictionary<TKey,TValue>
  • IEqualityComparer
Hashtable Class (System.Collections) (2024)

FAQs

What is System Collections HashTable? ›

Represents a collection of key/value pairs that are organized based on the hash code of the key.

What is a hash table in collections? ›

The Hashtable class in Java is one of the oldest members of the Java Collection Framework. A hash table is an unordered collection of key-value pairs, with a unique key for each value. In a hash table, data is stored in an array of list format, with a distinct index value for each data value.

Is HashTable deprecated in Java? ›

HashTable has been deprecated. As an alternative, ConcurrentHashMap has been provided. It uses multiple buckets to store data and hence much better performance than HashTable.

Which is faster, dictionary or HashTable? ›

A Dictionary<TKey,TValue> of a specific type (other than Object) provides better performance than a Hashtable for value types. This is because the elements of Hashtable are of type Object; therefore, boxing and unboxing typically occur when you store or retrieve a value type.

What is the difference between Hashtable and HashMap classes in collection framework? ›

HashMap is non-synchronized. It is not thread-safe and can't be shared between many threads without proper synchronization code whereas Hashtable is synchronized. It is thread-safe and can be shared with many threads.

What is the purpose of Hashtable? ›

A hash table is a data structure that is used to store keys/value pairs. It uses a hash function to compute an index into an array in which an element will be inserted or searched. By using a good hash function, hashing can work well.

What is the difference between tables and collections? ›

How does a collection differ from a table? Instead of tables, a MongoDB database stores its data in collections. A collection holds one or more BSON documents. Documents are analogous to records or rows in a relational database table.

Why are hash tables so good? ›

In many situations, hash tables turn out to be on average more efficient than search trees or any other table lookup structure. For this reason, they are widely used in many kinds of computer software, particularly for associative arrays, database indexing, caches, and sets.

What is the purpose of hash based collection? ›

Java's hash-based data structures, HashSet and HashMap use hash tables to store elements and keys. The point of a hash code is that it can be computed in constant time, so hashtables allow very fast lookups.

What is the drawback of Hashtable? ›

One of the main challenges of using a hash table is how to deal with collisions, which occur when two or more keys map to the same index in the table. This can reduce the performance and increase the complexity of the hash table, as you need to implement a strategy to resolve the conflicts.

What should I use instead of Hashtable in Java? ›

If a thread-safe implementation is not needed, it is recommended to use HashMap in place of Hashtable . If a thread-safe highly-concurrent implementation is desired, then it is recommended to use ConcurrentHashMap in place of Hashtable .

Which is faster, HashMap or Hashtable? ›

HashMap is not synchronized, therefore it's faster and uses less memory than Hashtable. Generally, unsynchronized objects are faster than synchronized ones in a single threaded application.

Can a Hashtable have duplicate keys? ›

There are no restrictions on the type of a key or value. Duplicate keys are not supported.

Is Hashtable fail fast? ›

Hashtable is fail-fast, if you iterate the Hashtable while add or remove one element without using the iterator, then you will get ConcurrentModificationException.

Is Hashtable faster than ArrayList? ›

This operation has an O(n), i.e., linear complexity. Removing an item from a HashTable is O(1), so faster than an ArrayList. So, on average, HashTable performs better than an ArrayList, but there are use cases, when an ArrayList is the better choice, just like there are cases when a LinkedList is an even better choice.

What is the difference between collections synchronizedMap and Hashtable? ›

Hashtable synchronizes each and every method in the java. util. Map interface, while Collections. synchronizedMap(hash_map) returns a wrapper object containing synchronized methods delegating calls to the actual hash_map (correct me if I am wrong).

What is a hash table in operating system? ›

A hash table is a type of data structure in which information is stored in an easy-to-retrieve and efficient manner. In the key-value method, keys are assigned random indexes where their values are stored in an array. The index is the information of where exactly in the array the value is stored.

What is a HashMap in collections? ›

HashMap in Java stores the data in (Key, Value) pairs, and you can access them by an index of another type (e.g. an Integer). One object is used as a key (index) to another object (value). If you try to insert the duplicate key in HashMap, it will replace the element of the corresponding key.

Top Articles
Everything You Need to Know About Money in the Philippines
Top-Down versus Bottom-Up Budgeting - Datarails
English Bulldog Puppies For Sale Under 1000 In Florida
Devon Lannigan Obituary
Geodis Logistic Joliet/Topco
35105N Sap 5 50 W Nit
Sitcoms Online Message Board
Raid Guides - Hardstuck
Builders Best Do It Center
What Happened To Maxwell Laughlin
Huge Boobs Images
Cvb Location Code Lookup
Q33 Bus Schedule Pdf
SF bay area cars & trucks "chevrolet 50" - craigslist
Zoe Mintz Adam Duritz
ELT Concourse Delta: preparing for Module Two
Purdue 247 Football
John Chiv Words Worth
Egizi Funeral Home Turnersville Nj
8005607994
Directions To Cvs Pharmacy
[PDF] PDF - Education Update - Free Download PDF
Rogue Lineage Uber Titles
Phantom Fireworks Of Delaware Watergap Photos
Pawn Shop Moline Il
Dtm Urban Dictionary
Nk 1399
FAQ's - KidCheck
Lbrands Login Aces
Buhl Park Summer Concert Series 2023 Schedule
Maisons près d'une ville - Štanga - Location de vacances à proximité d'une ville - Štanga | Résultats 201
Marlene2295
The Monitor Recent Obituaries: All Of The Monitor's Recent Obituaries
Perry Inhofe Mansion
Sun Haven Pufferfish
Gas Prices In Henderson Kentucky
Tamil Play.com
Uhaul Park Merced
Santa Cruz California Craigslist
Kgirls Seattle
Leatherwall Ll Classifieds
Directions To Cvs Pharmacy
[Teen Titans] Starfire In Heat - Chapter 1 - Umbrelloid - Teen Titans
Squalicum Family Medicine
705 Us 74 Bus Rockingham Nc
Gw2 Support Specter
Crigslist Tucson
The Machine 2023 Showtimes Near Roxy Lebanon
Aurora Southeast Recreation Center And Fieldhouse Reviews
Erica Mena Net Worth Forbes
Black Adam Showtimes Near Kerasotes Showplace 14
Latest Posts
Article information

Author: Jeremiah Abshire

Last Updated:

Views: 5810

Rating: 4.3 / 5 (74 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Jeremiah Abshire

Birthday: 1993-09-14

Address: Apt. 425 92748 Jannie Centers, Port Nikitaville, VT 82110

Phone: +8096210939894

Job: Lead Healthcare Manager

Hobby: Watching movies, Watching movies, Knapping, LARPing, Coffee roasting, Lacemaking, Gaming

Introduction: My name is Jeremiah Abshire, I am a outstanding, kind, clever, hilarious, curious, hilarious, outstanding person who loves writing and wants to share my knowledge and understanding with you.