Java Program to Insert an Item to the Stack Represented by the LinkedList

You are currently viewing Java Program to Insert an Item to the Stack Represented by the LinkedList

Java program to insert an item to the stack represented by the LinkedList

// Java program to insert an item to the stack represented 
// by the LinkedList

import java.util.LinkedList;

public class Main {
  public static void main(String[] args) {
    LinkedList < String > stkList = new LinkedList < > ();

    stkList.push("One");
    stkList.push("Two");
    stkList.push("Three");
    stkList.push("Four");

    System.out.println(stkList);
  }
}

Output

[Four, Three, Two, One]

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply