Java Program to Create a Stack With Hybrid Items Using Stack Collection

You are currently viewing Java Program to Create a Stack With Hybrid Items Using Stack Collection

Java program to create a stack with hybrid items using Stack collection

// Java program to create a stack with hybrid items 
// using Stack collection

import java.io.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Stack stck = new Stack();

    stck.push(1);
    stck.push("Two");
    stck.push(3.14);
    stck.push(true);

    System.out.println("Stack elements: \n" + stck);
  }
}

Output

Stack elements: 
[1, Two, 3.14, true]

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