How to get first element from stack in Java

1 Answer

0 votes
import java.util.Stack;

public class MyClass {
    public static void main(String args[]) {
        Stack<String> st = new Stack<>();
        
        st.push("java");
        st.push("c++");
        st.push("c#");
        st.push("python");
        
        String s = st.peek();

        System.out.println(s);
    }
}




/*
run:

python

*/

 



answered Apr 1, 2021 by avibootz
...