Stack
Stack<Integer> stack = new Stack<>();
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);
stack.forEach(n->System.out.print(n));
System.out.println();
while (!stack.isEmpty()) {
System.out.print(stack.pop());
}
Queue
Queue<Integer> queue = new LinkedBlockingDeque<>();
queue.add(1);
queue.add(2);
queue.add(3);
queue.add(4);
queue.forEach(n->System.out.print(n));
System.out.println();
while(!queue.isEmpty()) {
System.out.print(queue.poll());
}