@Test void reverse() { Stack<String> stack = StackUtils.push(new Stack<>(), "a", "b", "c"); Stack<String> reversed = StackUtils.reverse(stack); Assertions.assertSame(stack, reversed); Assertions.assertEquals(3, stack.size()); Assertions.assertEquals("a", stack.pop()); }
public static <T> Stack<T> reverse(Stack<T> stack) { List<T> reversed = new ArrayList<>(stack); Collections.reverse(reversed); stack.clear(); for (T element : reversed) { stack.push(element); } return stack; }
StackUtils { public static <T> Stack<T> reverse(Stack<T> stack) { List<T> reversed = new ArrayList<>(stack); Collections.reverse(reversed); stack.clear(); for (T element : reversed) { stack.push(element); } return stack; } }
StackUtils { public static <T> Stack<T> reverse(Stack<T> stack) { List<T> reversed = new ArrayList<>(stack); Collections.reverse(reversed); stack.clear(); for (T element : reversed) { stack.push(element); } return stack; } private  StackUtils(); }
StackUtils { public static <T> Stack<T> reverse(Stack<T> stack) { List<T> reversed = new ArrayList<>(stack); Collections.reverse(reversed); stack.clear(); for (T element : reversed) { stack.push(element); } return stack; } private  StackUtils(); @SafeVarargs static Stack<T> push(Stack<T> stack, T... values); static Stack<T> popSilently(Stack<T> stack, int amount); static Stack<T> fill(Stack<T> stack, T object, int amount); static Stack<T> reverse(Stack<T> stack); static Stack<T> of(Collection<? extends T> collection); }
StackUtils { public static <T> Stack<T> reverse(Stack<T> stack) { List<T> reversed = new ArrayList<>(stack); Collections.reverse(reversed); stack.clear(); for (T element : reversed) { stack.push(element); } return stack; } private  StackUtils(); @SafeVarargs static Stack<T> push(Stack<T> stack, T... values); static Stack<T> popSilently(Stack<T> stack, int amount); static Stack<T> fill(Stack<T> stack, T object, int amount); static Stack<T> reverse(Stack<T> stack); static Stack<T> of(Collection<? extends T> collection);  }