The Hashtable class in Java is a specific implementation of an abstract dictionary class. This is a data structure similar to the Java HashMap, which can store a collection of items (objects) as key value pairs (records).

Key objects must implement the hashCode() and equivalent() methods to store and retrieve the hash table values. In other words: The hash table can only store key objects that overwrite the hashCode() methods and equivalent methods defined by the object class.

The main difference between Hashtable and HashMap is the way they work with thread access.

The Hashtable class is a synchronized class, which means it is wireless. Multiple wires cannot access the same specimen of the Hashtable class at the same time.

The HashMap class is not synchronized, which means it is not thread-resistant. Multiple threads can access a single instance of the HashMap class at the same time. It is therefore safe to use it only when a wire uses an object.

Java Hashtable has been added to JDK 1.0 and is included in the java.util.Hashtable package. Before JDK 1.2, hash tables were used to compare keys with values.

Later Java version 1.2 Hashtable was adapted to implement the map interface. For example, Hashtable has been integrated as part of the Java collection. However, this does not exactly correspond to the Java Collections Framework, it is now considered a hereditary class.

Java Hash Table Hierarchy

The Hashtable class extends the Dictionary class and implements the Folder, Cloneable and Serializable interfaces. The diagram of the hash table hierarchy in Java is shown in the following figure.

Java Hashtable

ClassChopped declaration

The hash table in Java is a generic class created with JDK 1.5, which can be declared as follows

public class Hashtable<K,V>
expands dictionary<K,V>
implements card<K,V>, cloning, serializable

Here Hashtable accepts two parameters K and V, where K stands for the key type and V defines the value type.

Reverse characteristics

There are several features of Hashtable in Java that you should know about its use.

1. The basic data structure for Java Hashtable is just a hashtable.

2. The placement order will not be saved. This means that the insertion sequence is not supported.

3. Duplicate keys are not allowed, but values can be duplicated.

4. Heterogeneous objects are allowed for both keys and values.

5. Zero is not allowed for the key or values. When we try to save the Zero key or value, we get a runtime exception called Zero Point Exception.

6. Java Hashtable implements serializable and cloned interfaces, but no random access.

7. All methods available in Hashtable are synchronized. So the Hashtable object is safe for the wires.

8. Hashtable is the best choice if our joint operation is a search operation.

9. Because Hashtable is synchronized, operations are slower than those of HashMap in Java.

JavaHash-class constructors

The Hashtable class defines the following designers:

1. Hashtable() : This shape of the designer makes it possible to build a new empty hash object with an initial standard capacity of 11 and a load factor of 0.75.
To save a string as a key and an entire object as a value, you can create a hash object in the form :

Hashtable<String,Integer> ht = new hashtable<>() ;

The initial standard capacity of this chopped object is 11 and the load factor is 0,75.

2. Hashtable (Initial Power) : This builder creates a new empty hash bowl with a specified initial capacity and a standard load factor of 0,75. If the initial capacity is less than zero, an exception called IllegalArgumentException is triggered.

3. Chopping table (initial capacity int, floating load factor) : This designer creates a new empty hash table with a certain initial load capacity and load factor.

4. Hashbabel (card m) : This form of constructor creates a new hash file with the same attributes as the given map. If the specified card is zero, the NullPointerException is thrown.

Hash methods on Java

The Java hashtable class defines the following inherited methods:

1. invalid clear(() : It is used to clean up all key value pairs in the hashback.

2. Clone the object() : This method is used to create a flat copy of this hash file.

3. V well (key K, value V) : This method is used to display key value pairs in Hashbabel.

4. Invalid Issue Card : This method copies into the hashball all key value pairs (mapping) of the specified card.

5. boolean isEmpty() : Matches if there’s no record in Hashtable.

6. int Size() : This method is used to obtain the number of key value pairs in Hashbabel.

7. V (Delete object key) : This method is used to remove the key (and its value) from the hash table.

8. Boolean deletion (object key, object value) : With this method, the record for the specified key is only erased if it is currently associated with the specified value.

9. Replace V (K-button, V-value) : This method is only used to replace a record for a particular key if it is currently linked to a value.

10. Boolean replacement (key K, V old value, V new value) : This method replaces a key value pair for a specified key only if it is currently associated with the specified value.

11. Boolean contains (value of the object) : This method checks the hash table and shows the truth if the hash table contains the specified value.

12. Boolean contains keys (object keys) : This method searches the hash table and returns where if the specified key object is in the hash table.

13. Boolean and Boolean: This method searches for a hash table and displays the truth when the hash table displays one or more keys for that value.

14. Elements of the enumerationn() : This method lists the values in this hash table.

15. Enumeration key() : This method returns the most important enumeration in this hashtable.

16. Setting<Card.Input<K,V>>> InputSet() : This method shows the type of set or collection of commands in this map.

17. install keySet() : Returns the set of keys contained in this card.

18. Collective values() : Displays the set of values on this map.

19. V get(object key) : Returns the value associated with the specified key. It returns zero if the key is not related to it.

20. Boolean equations (object o) : Used to compare the object specified for equality, as defined in the chart interface.

21. int hashCode() : This method returns the value of the hash code as defined in the card interface.

22. lanyard() : This method is used to convert hashable objects, in the form of a set of records between square brackets and separated by ASCII characters (comma and space), into a string and return that string.

Java programs chopable

Let’s look at several examples of programs for performing hashtable-based operations on Java.

1. Let’s create a program in which we perform various operations, such as adding, deleting, checking if the hashtable is empty or not, before adding items, and the size.

In this example we make a constructor with the standard initial capacity 11 and a load factor of 0,75. For a better understanding, refer to the source code.

Program source code 1 :

import java.util.hashtable;

public class HashtableEx [
public static void main(String[] args)
[
// Create a Hashtable object.
Hashtable<Integer, String> ht = new Hashtable<Integer, String>();

// The hashtable control is empty or not.
boolean isEmpty = ht.isEmpty();
System.out.println(Hashtable empty: +isEmpty) ;

// Add records to the hash table using the well() method.
ht.put(1, 1); // ht.size() is equal to 1.
ht.put(2, 2); // ht.size() is equal to 2.
ht.put(3, 3); // ht.size() is equal to 3.
ht.put(4, Four); // ht.size() is equal to 4.
ht.put(5, Five); // ht.size() is equal to 5.
ht.put(6, Six); // ht.size() is equal to 6.

System.out.println(Show records in hash table: +ht);
int size = ht.size();
System.out.println(Hash table size: +size) ;

// Erase the last record.
Line removeE = ht.remove(6);
System.out.println(Removed record: +removeE);
System.out.println(Updated records in the hash table: +ht) ;

// Received value 4.
Line getValue = ht.get(4);
System.out.println(Get value 4: +getValue);
System.out.println(Get value 2: +ht.get(2)));
}
}

A way out:
If the hash table is empty: True
Display data in the hash table : {6=Permanent, 5=Five, 4=Four, 3=Tree, 2=Two, 1=One}
Diamond table size: 6
Remote recording : Six updated
entries in the hashtable : {5= Five, 4= Four, 3= Three, 2= Two, 1= One}
Received value 4 : Four received
value 2 : Two

As you can see from the program output, the insertion sequence is not saved in the hash table. Internally, a separate keyash code is generated for each record and records are indexed to the keyash code to increase efficiency.

2. Let’s create another program in which we will perform different operations based on methods such as replace(), containsKey() and containsValue().

Program source code 2 :

import java.util.hashtable ;
public class HashtableEx2 [
public static empty head(string[] args)
[
// Create a Hashtable object.
Hash-table<String, Whole> ht = new hash-table<>() ;

ht.put(John, 20);
ht.put(Shubh, 30);
ht.put(Peter, 25);
ht.put(Low, 15);
ht.put(Jonshan, 40) ;

System.out.println(Original snapshot table entries: +ht) ;

// Replace the record for the key specified in the hash table.
Replace an integer = ht.replace(Peter, 60);
System.out.println(Replace the record with the specified key: + replace);
System.out.println(Updated records in the hash table: +ht) ;

// Check the specified key that exists in the hash table.
Boolean containsKey = ht.containsKey(Shubh);
System.out.println(Is the Shubh key in the hash table: +containsKey) ;

// Check the default value in the hash table.
boolean containsValue = ht.containsValue(40);
System.out.println(Is the value 40 in the hash table: +containsValue);
}
}

A way out:
Original hashtable entries : {John=20, Johnshan=40, Shubh=30, Deep=15, Peter=25}
Replace the record with the specified key: 25
Updated hash table entries : {John=20, Jonshan=40, Shubh=30, Deep=15, Peter=60}
Shubh key in hash table: true
value 40 in hash table: true

3. Let’s take an example program in which we iterate the keys, values and input data of the hash table using iterator(), keySet(), values() and entrySet().

Program source code 3 :

Importjava.util.hashtable; Importjava.util.Iterator; Importjava.util.Map.Entry ;

public class HashtableEx {
public static empty head(string[] args)
{
Hashtable<String, Integer> ht = new Hashtable<>() ;

ht.put(John, 20);
ht.put(Shubh, 30);
ht.put(Peter, 25);
ht.put(Low, 15);
ht.put(Jonshan, 40) ;

System.out.println(Original snapshot table entries: +ht) ;

// Iterate the hash table elements with the iterator() method.
System.out.println(Iterating hash table keys :);
Iterator itr = ht.keySet().iterator() ;
while(itr.hasNext())
{
System.out.println(itr.next())) ;
}
System.out.println(n) ;

System.out.println(Iteration of hash values:);
Iterator itrValue = ht.values().iterator();
while(itrValue.hasNext()).
{System.out.println(itrValue.next());}System.out.println(itrValue.next());{System.out.println(itrEintrag.next());System.out.println(itrEintrag.next());Iterator<Enter<String, integer>>> itrEnter = ht.entrySet().iterator();while(itrEntry.hasNext()){System.out.println(itrEintrag.next());}}}}

A way out:
Original hashtable entries : {John=20, Johnshan=40, Shubh=30, Deep=15, Peter=25}
Iteration keys for the hash table:
John
Johnshan
Thrust
Weak
Peter

Hashtabel iteration values :
20
40
30
15
25

Iterative hashtable entries
John=20
Johnshan=40
Shubh=30
Deep=15
Peter=25

I hope this manual has covered Hashbet’s main points in Java with sample programs. I hope you understand how to iterate Hashbyl.
Thanks for reading!

this christmas summary,index of this christmas movie,this christmas 2007 google docs,this christmas 2007 full movie free,this christmas free movie online,this christmas on bet,christmas movies 2008,this christmas full movie online free,this christmas soundtrack,this christmas cast 2019,preston a. whitmore ii,how old was lauren london in this christmas,how old was chris brown in 2007,this christmas 2007 google drive,this christmas movie review,this christmas review,this christmas movie,this christmas (2007 cast),this christmas sequel,this christmas full movie,where was this christmas filmed

You May Also Like

ūü•á¬†Export Data to Text Format in Excel¬† Detailed Guide ‚Ė∑ 2020

Working with this Microsoft Windows program will undoubtedly give you a number…

6 Best Laptops for Major Informatics ‚Äď May 2020.

There are a few things you should consider before buying a laptop…

7 Best Cheap Gaming TVs in 2020.

By 2020, even cheap TVs will be perfect for gaming, no matter…

An elegant day of the week picker inspired by Google’s clock app

Material day selector Builder inspired by the day in the integrated Android…