Advances iterator to the end, returning the last element. @return the last element of iterator @throws NoSuchElementException if the iterator is empty
(Iterator<T> iterator)
| 828 | * @throws NoSuchElementException if the iterator is empty |
| 829 | */ |
| 830 | public static <T> T getLast(Iterator<T> iterator) { |
| 831 | while (true) { |
| 832 | T current = iterator.next(); |
| 833 | if (!iterator.hasNext()) { |
| 834 | return current; |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | /** |
| 840 | * Advances {@code iterator} to the end, returning the last element or |