code: public static <T> Set<T> iteratorToSet(Iterator<T> iterator) {
          Set<T> set = new HashSet<>();
          while (iterator.hasNext()) {
              set.add(iterator.next());
          }
          return set;
      }
docs: Convert an {@link Iterator} to a {@link Set}.
  
  @param iterator The iterator
  @param <T>      The type
  @return The set