P02 { public static <T> T secondLastRecursion(LinkedList<T> list) { if (list.size() < 2) { throw new NoSuchElementException("Can't find secondLast element from a list with less than 2 elements"); } if (list.size() == 2) { return list.getFirst(); } return secondLastRecursion(new LinkedList<>(list.subList(1, list.size()))); }  static T secondLast(List<T> list); static T secondLastRecursion(LinkedList<T> list);  }
@Test public void shouldFindSecondLastElementFromALinkedList() throws Exception { LinkedList<Integer> numbers = linkedList(1, 2, 11, 4, 5, 8, 10, 6); assertThat(P02.secondLastRecursion(numbers), is(equalTo(10))); }