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)
| 877 | |
| 878 | |
| 879 | public static <T> T getLast(Iterator<T> iterator) { |
| 880 | while (true) { |
| 881 | T current = iterator.next(); |
| 882 | if (!iterator.hasNext()) { |
| 883 | return current; |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * Advances {@code iterator} to the end, returning the last element or |