Stack Java Library Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In Java, there are multiple ways to use built-in libraries for Stack.Stack Class It is a legacy collection from early Java versions. It is outdated and rarely used in modern JavaIt's synchronized and thread-safe, which can be slower in single-threaded applications like doing data structures and CP problems.Synchronized by default, which might add unnecessary overhead if thread-safety isn't required.ArrayDeque Class Faster performance for single-threaded scenarios.Resizable array-backed without the overhead of synchronization.More flexible, as it can also be used as a queue.Cannot store null elements (throws NullPointerException if attempted).If you are not sure for a coding problem, you may always use this for fast performance. Java import java.util.ArrayDeque; import java.util.Deque; public class GFG { // Driver Code public static void main(String[] args) { // Creating an ArrayDeque to use // as a Stack Deque<Integer> s = new ArrayDeque<Integer>(); // Inserting elements in the Stack // using push() operation s.push(17); s.push(19); s.push(15); // Printing the elements System.out.println("Stack after insertion: " + s); // Removing elements from the Stack // using pop() operation s.pop(); System.out.println("Stack after deletion: " + s); s.pop(); System.out.println("Stack after deletion: " + s); } } OutputStack after insertion: [15, 19, 17] Stack after deletion: [19, 17] Stack after deletion: [17] LinkedList ClassAlso implements Deque and can be used as a stack, queue, or double-ended queue. It is a doubly-linked list implementation.We use LinkedList when we want to leverage linked list operations like insertions and deletions are required at both ends.More memory overhead as we used linked list.FeatureStackArrayDequeLinkedListSynchronizationYesNoNoBacking StructureArray (Vector)Resizable ArrayDoubly-Linked ListNull ElementsYesNoYesUse as QueueNoYesYesPerformanceSlowerFastestModerateMemory OverheadModerateLowHighThread SafetySynchronizedNot thread-safeNot thread-safe Comment More info K kartik Follow Improve Article Tags : Java Java-Collections Explore Java BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOP & InterfacesClasses and Objects in Java10 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking15+ min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like