HashSet & How It Works Internally in Java. Bengali-Ep:19 #bengalitutorial #learnjava #bengali
Hi,
Hope you are all doing great. Let's learn together.
Join Telegram: ? https://t.me/contactajoydebnath
Chapters ❤
0:00 Introduction
00:26 How HasSet use HashMap internally
17:43 HashTable DataStructure
Note:
Java was developed by Sun Microsystems (which is now a subsidiary of Oracle) in the year 1995. James Gosling is known as the father of Java. Before Java, its name was Oak. Since Oak was already a registered company, James Gosling and his team changed the name from Oak to Java.
Video Links --
HashSet, Its Methods & How It Works Internally in Java: https://youtu.be/nQOLOBlgw-w
Core Java Playlist: https://www.youtube.com/playlist?list=PL0LQjbMWLlS3AVp2LglGSvfV6ieUSsNMp
Spring Playlist: https://www.youtube.com/playlist?list=PL0LQjbMWLlS3tXLVZBuLmsMJ9dU6JNtGD
Document Link -
https://docs.google.com/document/d/1SBrXs1P6empuOLcHWtDw-j4pmgeZgbm3ugvBplH1Jok/edit?usp=sharing
Like, Comment, Share, and Subscribe.
Thank you again.
STS Link:
https://spring.io/tools
JDK Link:
https://www.oracle.com/java/technologies/downloads/
HashSet
Java HashSet class is used to create a collection that uses a hash table for storage. The HashSet class implements the Set interface, backed by a hash table which is actually a HashMap instance.
Hierarchy
public class HashSet extends AbstractSet implements Set, Cloneable, Serializable
The important points about the Java HashSet class are:
HashSet stores the elements by using a mechanism called hashing.
HashSet contains unique elements only.
HashSet allows a null value.
HashSet class is non-synchronized.
HashSet doesn't maintain the insertion order. Here, elements are inserted on the basis of their hashcode.
Methods
Boolean add(E e) It is used to add the specified element to this set if it is not already present.
Void clear() It is used to remove all of the elements from the set.
Boolean contains(Object o) It is used to return true if this set contains the specified element.
Boolean isEmpty() It is used to return true if this set contains no elements.
Iterator iterator() It is used to return an iterator over the elements in this set.
Boolean remove(Object o) It is used to remove the specified element from this set if it is present.
Int size() It is used to return the number of elements in the set.
…….ETC
Internal working of a HashSet:
All the classes of the Set interface are internally backed up by Map. HashSet uses HashMap for storing its object internally. You must be wondering that to enter a value in HashMap we need a key-value pair, but in HashSet, we are passing only one value.
Storage in HashMap: The value we insert in HashSet acts as a key to the map Object and for its value, java uses a constant variable. So in the key-value pair, all the values will be the same.
add() method of the HashSet class internally calls the put() method of backing the HashMap object by passing the element you have specified as a key and constant “PRESENT” as its value.
remove() method also works in the same manner. It internally calls the remove method of the Map interface.
Hash Table
The Hash table data structure stores elements in key-value pairs where
Key- unique identifier that is used for indexing the values.
Value - data that are associated with keys.
What is Hashing?
It is the process of converting an object into an integer value. The integer value helps in indexing.
In a hash table, a new index is processed using the keys. And, the element corresponding to that key is stored in the index.
Let k be a key and hashFunction(k) be a hash function. Here, hashFunction(k) will give us a new index to store the element linked with k.
In a hash table, a new index is processed using the keys. And, the element corresponding to that key is stored in the index. This process is called hashing.
hash collision
When the hash function generates the same index for multiple keys, there will be a conflict (what value to be stored in that index). This is called a hash collision.
How to solve collision
Collision resolution by chaining
Open Addressing: Linear/Quadratic Probing and Double Hashing
Collision resolution by chaining
In chaining, if a hash function produces the same index for multiple key, these elements are stored in the same index by using a linked list.
If j is the slot for multiple elements, it contains a pointer to the head of the list of elements. If no element is present, j contains NULL.
**The initial default capacity of HashSet is 16, and the load factor is 0.75.
Initial Capacity: The initial capacity means the number of buckets when hashtable (HashSet internally uses hashtable data structure) is created.
Load Factor: The load factor is a measure of how full the HashSet is allowed to get before its capacity is automatically increased.
**If the initial capacity is 16 and the load factor is 0.75 then the number of buckets will automatically get increased when the table has 12 elements in it.
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «HashSet & How It Works Internally in Java. Bengali-Ep:19 #bengalitutorial #learnjava #bengali», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.