code: public static <T> T getLast(Iterator<T> iterator) {
      while (true) {
        T current = iterator.next();
        if (!iterator.hasNext()) {
          return current;
        }
      }
    }
docs: Advances {@code iterator} to the end, returning the last element.
  
  @return the last element of {@code iterator}
  @throws NoSuchElementException if the iterator is empty