0

I was going through the internal functionality of HashSet I came to know that it actually internally use HashMap. But in another post link reference given below, I noticed it is actually using hashtable in order to calculate the internal capacity and load factor.

I also have gone through this post but it doesn't help me much.

Now I am very much confused here is it using HasMap or hashtable internally. please help me out with the proper clarification.

Post on StackOverflow

Calculating load factor and internal capacity of a HashSet

Eran
  • 387,369
  • 54
  • 702
  • 768
Rohit Sharma
  • 71
  • 2
  • 17
  • Perhaps you missed this in the second link you provided: "The HashSet class implements the Set interface, backed by a hash table **which is actually a HashMap instance**" – Eran Jul 15 '20 at 10:06
  • It is combination of both. Everything, even if HashMap has internally HashTable. So hashset is made using both. https://www.geeksforgeeks.org/internal-working-of-sethashset-in-java/ but to summarize, you can call it HashTable in the end. Otherwise, hashing won't work – Aakash Patel Jul 15 '20 at 10:08
  • `Hashtable` and `HashMap` are both JDK classes that implement the hash table data structure. `HashSet` uses `HashMap` internally. It does not use `Hashtable`. – Eran Jul 15 '20 at 10:11
  • @Eran Thanks for the reply can you tell me the exact difference between Hashtable and hashtable (Lower case) ? – Rohit Sharma Jul 15 '20 at 10:16
  • 1
    @RohitSharma `Hashtable` is a Java class. "hash table" does not refer to any specific Java class - it refers to a data structure. – Eran Jul 15 '20 at 10:18
  • @Eran ok I got it now thanks again. – Rohit Sharma Jul 15 '20 at 10:24

0 Answers0