📜  Java.util.Hashtable类

📅  最后修改于: 2020-11-14 06:17:46             🧑  作者: Mango


介绍

java.util.Hashtable类实现了一个哈希表,该哈希表将键映射到值。以下是有关Hashtable的要点-

  • 在这种情况下,任何非空对象都可以用作键或值。

  • 如果要在哈希表中创建许多条目,则创建一个具有足够大容量的表可能比使表根据需要增长表的自动重新哈希处理更有效地插入条目。

类声明

以下是java.util.Hashtable类的声明-

public class Hashtable
   extends Dictionary
   implements Map, Cloneable, Serializable

类的构造函数

Sr.No. Constructor & Description
1

Hashtable()

This constructs a new, empty hashtable with a default initial capacity (11) and load factor (0.75).

2

Hashtable(int initialCapacity)

This constructs a new, empty hashtable with the specified initial capacity and default load factor (0.75).

3

Hashtable(int initialCapacity, float loadFactor)

This constructs a new, empty hashtable with the specified initial capacity and the specified load factor.

4

Hashtable(Map t)

This constructs a new hashtable with the same mappings as the given Map.

类方法

Sr.No. Method & Description
1 void clear()

This method clears this hashtable so that it contains no keys.

2 Object clone()

This method creates a shallow copy of this hashtable.

3 boolean contains(Object value)

This method tests if some key maps into the specified value in this hashtable.

4 boolean containsKey(Object key)

This method tests if the specified object is a key in this hashtable.

5 boolean containsValue(Object value)

This method returns true if this hashtable maps one or more keys to this value.

6 Enumeration elements()

This method returns an enumeration of the values in this hashtable.

7 Set> entrySet()

This method returns a Set view of the mappings contained in this map.

8 boolean equals(Object o)

This method compares the specified Object with this Map for equality, as per the definition in the Map interface.

9 V get(Object key)

This method returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

10 int hashCode()

This method returns the hash code value for this Map as per the definition in the Map interface.

11 boolean isEmpty()

This method tests if this hashtable maps no keys to values.

12 Enumeration keys()

This method returns an enumeration of the keys in this hashtable.

13 Set keySet()

This method returns a Set view of the keys contained in this map.

14 V put(K key, V value)

This method maps the specified key to the specified value in this hashtable.

15 void putAll(Map t)

This method copies all of the mappings from the specified map to this hashtable.

16 protected void rehash()

This method increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently.

17 V remove(Object key)

This method removes the key (and its corresponding value) from this hashtable.

18 int size()

This method returns the number of keys in this hashtable.

19 String toString()

This method returns a string representation of this Hashtable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters “, ” (comma and space).

20 Collection values()

This method returns a Collection view of the values contained in this map.

方法继承

此类从以下类继承方法-

  • java.util.Object