Vector and Stack predate the Collections framework: every method is synchronized even in single-threaded code, and Stack extends Vector so it exposes list operations like get(index) that break the stack discipline. ArrayDeque replaces both.
Vector<Integer> vector = new Vector<>();
vector.add(1);
vector.add(2);
Stack<Integer> stack = new Stack<>();
stack.push(10);
stack.push(20);
System.out.println("Vector: " + vector);
System.out.println("Stack (extends Vector): " + stack);
System.out.println("Stack pop order: " + stack.pop() + ", " + stack.pop());
System.out.println("Stack is also a List: " + (stack instanceof List));
Vector: [1, 2]
Stack (extends Vector): [10, 20]
Stack pop order: 20, 10
Stack is also a List: true
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27