HashSet implements the Set interface, which does not allow duplicate values in the collection. When we talk about HashSet, we should first ensure that the objects cover the equals () and hashCode () methods before being stored in HashSet, so as to compare whether the values of the objects are equal and ensure that no equal objects are stored in the collection.
The public boolean add(Object o) method is used to add elements to the collection. When the element value is repeated, it will immediately return false, and if it is added successfully, it will return true.
Hash table:
HashMap implements the Map interface and maps key-value pairs. Duplicate keys are not allowed in the map. Map interface has two basic implementations, HashMap and TreeMap. TreeMap keeps the order of objects, while HashMap cannot.
HashMap allows keys and values to be empty. HashMap is asynchronous, but the method provided by the collection framework can ensure the synchronization of HashMap, so that when multiple threads access HashMap at the same time, only one thread can change the mapping.
The public Object put(Object Key, Object value) method is used to add elements to the map.