Pages

Friday, September 19, 2025

Java Collection Framework - Stack in Java

 import java.util.*;

// Java Collection Framework of Stack

class StackB {

    public static void main(String[] args) {

        Stack<Integer> s = new Stack<>();

        s.push(1);

        s.push(2);

        s.push(3);

        

        System.out.println(s); // Before pop

        

        while(!s.isEmpty()) {

            System.out.println(s.peek());

            s.pop();

        } 

        

        System.out.println(s);  // After pop 

    }

}

No comments:

Post a Comment

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...