code: public static <T> List<T> toList(Iterator<T> iter) {
      List<T> buf = new ArrayList<>();
      while (iter.hasNext()) {
        buf.add(iter.next());
      }
      return buf;
    }
docs: Returns a list with the data from the iterator.