P01 { public static <T> T lastRecursive(List<T> elements) { if (elements == null || elements.isEmpty()) { throw new NoSuchElementException(); } if (elements.size() == 1) { return elements.get(0); } return lastRecursive(elements.subList(1, elements.size())); }  static T last(List<T> elements); static T last(LinkedList<T> elements); static T lastRecursive(List<T> elements);  }
@Test public void shouldFindLastElementFromAListOfAlphabetsUsingRecursion() throws Exception { assertThat(P01.lastRecursive(asList("a", "b", "c", "d")), is(equalTo("d"))); }