Convert an iterator to a Set. The iterator will become
exhausted of elements after making this conversion.

@param self an iterator
@return a Set
@since 1.8.0
17832
public static <T> Set<T> toSet(Iterator<T> self) {
        Set<T> answer = new HashSet<T>();
        while (self.hasNext()) {
            answer.add(self.next());
        }
        return answer;
    }
1073066
public static <T> Collector<T, Set<T>> toSet() {
    return new Collector<T, Set<T>>() {
      @Override
      public Set<T> collect(Stream<? extends T> stream) {
        return Sets.newHashSet(stream.iterator());
      }
    };
  }
356407
public static Iterator iterator(final DefaultTableModel self) {
        return new Iterator() {
            private int row = 0;

            public boolean hasNext() {
                return row > -1 && row < self.getRowCount();
            }

            public Object next() {
                int cols = self.getColumnCount();
                Object[] rowData = new Object[cols];
                for (int col = 0; col < cols; col++) {
                    rowData[col] = self.getValueAt(row, col);
                }
                row++;
                return rowData;
            }

            public void remove() {
                if (hasNext()) self.removeRow(row--);
            }
        };
    }
320414
@Override
    public Set<T> next() {
        Set<T> subset = new LinkedHashSet<>();
        next(subset);
        return subset;
    }
900998
public Iterator<V> values()
  {
    ValueIterator<K,V> iter = new ValueIterator<K,V>(this);
    iter.init(this);
    return iter;
  }
116540
public static <T> Set<T> asSynchronized(Set<T> self) {
        return Collections.synchronizedSet(self);
    }
624322
public static <T> Iterator<T> toUnique(Iterator<T> self) {
        return new UniqueIterator<T>(self, null);
    }
159418
public static <T> SortedSet<T> asSynchronized(SortedSet<T> self) {
        return Collections.synchronizedSortedSet(self);
    }
1051204
public static <K, V> Map<K, V> collectEntries(Iterator<?> self) {
        return collectEntries(self, Closure.IDENTITY);
    }
741357
public static <E> Set<Set<E>> powerSet(Set<E> s) {
    if (s.isEmpty()) {
      Set<Set<E>> h = new HashSet<Set<E>>();
      Set<E> h0 = new HashSet<E>(0);
      h.add(h0);
      return h;
    } else {
      Iterator<E> i = s.iterator();
      E elt = i.next();
      s.remove(elt);
      Set<Set<E>> pow = powerSet(s);
      Set<Set<E>> pow1 = powerSet(s);
      // for (Iterator j = pow1.iterator(); j.hasNext();) {
      for (Set<E> t : pow1) {
        // Set<E> t = new HashSet<E>((Set<E>) j.next());
        t.add(elt);
        pow.add(t);
      }
      s.add(elt);
      return pow;
    }
  }
1040012
public Set<String> keySet(){
		HashSet<String> set=new HashSet<String>();
		Iterator<String> keys=keys();
		while(keys.hasNext()){
			set.add(keys.next());
		}
		return set;
	}
554073
public static <T> Set<T> toSet(final T[] array) {

    if (isNotEmpty(array)) {
      Set<T> set = new HashSet<T>(array.length);
      for (T element : array) {
        set.add(element);
      }
      return set;
    } else {
      return new HashSet<T>(0);
    }
  }
700175
public final Set<K> keySet() {
	return new AbstractSet<K>() {
	    public Iterator<K> iterator() {
		final Iterator<Map.Entry<K,V>> ite = entryIterator();
		return new Iterator<K>() {
		    public boolean hasNext() { return ite.hasNext(); }
		    public void    remove()  { ite.remove(); }
		    public K       next()    { return ite.next().getKey(); }
		};
	    }
	    public int size() {
		return size;
	    }
	};
    }
608115
@Override
	public Iterator<E> iterator() {
		combine();
		if(combined==null) {
			Set<E> emptySet = java.util.Collections.emptySet();
			return emptySet.iterator();
		}
		return combined.iterator();
	}
53081
public static <E> ArraySet<E> newArraySet(E... elements) {
        int capacity = elements.length * 4 / 3 + 1;
        ArraySet<E> set = new ArraySet<E>(capacity);
        Collections.addAll(set, elements);
        return set;
    }
128906
public static Iterator iterator(final MutableComboBoxModel self) {
        return new Iterator() {
            private int index = 0;

            public boolean hasNext() {
                return index > -1 && index < self.getSize();
            }

            public Object next() {
                return self.getElementAt(index++);
            }

            public void remove() {
                if (hasNext()) self.removeElementAt(index--);
            }
        };
    }
398424
public static Iterator iterator(final TableModel self) {
        return new Iterator() {
            private int row = 0;

            public boolean hasNext() {
                return row < self.getRowCount();
            }

            public Object next() {
                int cols = self.getColumnCount();
                Object[] rowData = new Object[cols];
                for (int col = 0; col < cols; col++) {
                    rowData[col] = self.getValueAt(row, col);
                }
                row++;
                return rowData;
            }

            public void remove() {
                throw new UnsupportedOperationException("TableModel is immutable.");
            }
        };
    }