Problem3_2 { public <T> List<T> reverse(List<T> list) { Stack<T> stack = new Stack<>(); list.forEach(stack::push); List<T> reversed = new LinkedList<>(); while (!stack.isEmpty()) { reversed.add(stack.pop()); } return reversed; }  List<T> reverse(List<T> list);  }
@Test public void shouldReverseALinkedList() throws Exception { List<Integer> numbers = IntStream.rangeClosed(1, 10).boxed().collect(toCollection(LinkedList::new)); List<Integer> reversedNumbers = new Problem3_2().reverse(numbers); assertThat(reversedNumbers, equalTo(Stream.of(10, 9, 8, 7, 6, 5, 4, 3, 2, 1).collect(toCollection(LinkedList::new)))); }