> For the complete documentation index, see [llms.txt](https://gyansetu-selenium.gitbook.io/selenium-testing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gyansetu-selenium.gitbook.io/selenium-testing/hashset.md).

# HashSet:

* &#x20; The HashSet class implements the Set interface. It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. \\
* HashSet doesn’t allow duplicates. If you try to add a duplicate element in HashSet, the old value would be overwritten.
* &#x20; HashSet allows null values however if you insert more than one nulls it would still return only one null value.

#### HashSet Methods:&#x20;

1\. boolean add(Element e): It adds the element e to the list. 2. void clear(): It removes all the elements from the lis .

3\. Object clone(): This method returns a shallow copy of the HashSet.

&#x20;4\. boolean contains(Object o): It checks whether the specified Object o is present in the list or not. If the object has been found it returns true else false.

&#x20;5\. boolean isEmpty(): Returns true if there is no element present in the Set.&#x20;

6\. int size(): It gives the number of elements of a Set.&#x20;

7\. boolean(Object o): It removes the specified Object o from the Set.

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTfodd4WmwvcIWYWbMe%2F-LTfppbUzS_kG__B9XG7%2Fimage.png?alt=media\&token=ada5718c-2fe5-4433-897d-87e51cd2ae70)

#### &#x20;Output:&#x20;

\[Java, Selenium, QTP]

&#x20;Is HashSet empty? false \[Selenium, QTP]

&#x20;Size of the HashSet: 2&#x20;

Does HashSet contains first element? False

#### &#x20;How to Iterate over a Set/HashSe

t Below example shows how to read all elements from the HashSet objects. You can iterate through HashSet by getting Iterator object. By calling iterator() method, you can get Iterator object.

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTfodd4WmwvcIWYWbMe%2F-LTfqMSiGoqD2W1VOpDu%2Fimage.png?alt=media\&token=20bba3e8-ea22-416a-b0f4-183bb206ffca)

#### &#x20;Output:&#x20;

Java

&#x20;Selenium

&#x20;QTP
