Iterators { public static <T> Optional<T> getFirst(Iterator<T> iterator) { return iterator.hasNext() ? Optional.<T> of(iterator.next()) : Optional .<T> absent(); } private  Iterators(); static Optional<T> getFirst(Iterator<T> iterator); static Optional<T> getLast(Iterator<T> iterator);  }
@Test public void getFirst() { assertThat(Iterators.getFirst(iteratorOf(1)).get(), is(1)); assertThat(Iterators.getFirst(iteratorOf(1, 2)).get(), is(1)); }