Java Collections Tutorials 05 | HashSet and LinkedHashSet in java | Java9s.com

preview_player
Показать описание
A Set is a collection of Unique elements.
Set implementation like HashSet, LinkedHashSet and TreeSet should not allow any duplicate object into it.
HashSet is only Unordered and UnSorted. LinkedHashSet is an ordered collection based on the insertion.
Coming to TreeSet, it sorts all its elements so they are ordered based on the sorting criteria.
HashSet is Unordered and Unsorted collection.

It does not allow duplicates and we cannot predict the iteration order.

Then linkedhashSet is ordered as it arranges the elements in the same order as they were inserted.

It also does not allow duplicates

The iterator fetches the elements as they were inserted. So, if you want a collection which should not allow duplicates and should maintain the order, then we can use LinkedHashSet

Complete Generics Tutorials playlist

Complete Java Beginners Tutorials:

Multithreading in Java tutorial:

Spring 3 MVC Framework tutorials:

Spring Framework Tutorials:

Design Patterns in Java:
Рекомендации по теме
Комментарии
Автор

Thanks for your great videos and wonderful explanations

RosalynAbankwah
Автор

can u explain for POJA class with two or more strings and int stored in hash set. Each comparsion we compare individually strings then equals and hash code how is it possible for multiple variables

jesuraj
Автор

Can we update the HashSet while iterating through the elements ? More specific while reverting the elements from the HashSet collecting I want to modify some of the elements, how do we do that ?

deepak