A HashSet is a collection of items where every item is unique, and it is found in the java.util package:

Example

Create a HashSet object called cars that will store strings:

import java.util.HashSet; // Import the HashSet class

HashSet<String> cars = new HashSet<String>();



Practice Excercise Practice now