Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9773,6 +9773,29 @@ public static <T> boolean push(List<T> self, T value) {
return true;
}


/**
* Returns the last item from the LinkedList.
* <pre class="groovyTestCase">
* def list = [3, 4, 2]
* assert list.last() == 2
* // check original is unaltered
* assert list == [3, 4, 2]
* </pre>
*
* @param self a List
* @return the last item from the List
* @throws NoSuchElementException if the list is empty and you try to access the last() item.
* @since 1.5.5
*/
public static <T> T last(LinkedList<T> self) {

if (self.isEmpty()) {
throw new NoSuchElementException("Cannot access last() element from an empty List");
}
return self.getLast();
}

/**
* Returns the last item from the List.
* <pre class="groovyTestCase">
Expand All @@ -9788,6 +9811,7 @@ public static <T> boolean push(List<T> self, T value) {
* @since 1.5.5
*/
public static <T> T last(List<T> self) {

if (self.isEmpty()) {
throw new NoSuchElementException("Cannot access last() element from an empty List");
}
Expand Down