code: private void readObject(java.io.ObjectInputStream s)
          throws java.io.IOException, ClassNotFoundException {
          // Read in any hidden serialization magic
          s.defaultReadObject();
  
          // Read in HashMap capacity and load factor and create backing HashMap
          int capacity = s.readInt();
          float loadFactor = s.readFloat();
          map = (((HashSet)this) instanceof LinkedHashSet ?
                 new LinkedHashMap<E,Object>(capacity, loadFactor) :
                 new HashMap<E,Object>(capacity, loadFactor));
  
          // Read in size
          int size = s.readInt();
  
          // Read in all elements in the proper order.
          for (int i=0; i<size; i++) {
              E e = (E) s.readObject();
              map.put(e, PRESENT);
          }
      }
docs: Reconstitute the <tt>HashSet</tt> instance from a stream (that is,
  deserialize it).