code: public static <T, C extends Collection<? super T>> C toCollection(
          Iterator<T> iterator, C collection)
      {
          Objects.requireNonNull(iterator, "The iterator is null");
          Objects.requireNonNull(iterator, "The collection is null");
          while (iterator.hasNext())
          {
              collection.add(iterator.next());
          }
          return collection;
      }
docs: Drains all elements that are provided by the given iterator
  into the given collection
  
  @param <T> The element type
  @param <C> The collection type
  @param iterator The iterator
  @param collection The target collection
  @return The given collection