Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Java Stack class peek() method

import java.util.Stack;

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

        // Add elements to Stack
        fruits.push("Apple");
        fruits.push("Banana");
        fruits.push("Mango");
         System.out.println("Stack: " + fruits);

        // Access element from the top
        String fruit = fruits.peek();
        System.out.println("Element at top: " + fruit);
    }
}
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Java #Stack #class #method
ADD COMMENT
Topic
Name
8+9 =