Search
 
SCRIPT & CODE EXAMPLE
 

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);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: on touch listener android 
Java :: how to get last element of array java 
Java :: decode base64 to file java 
Java :: printing arraylist 
Java :: how to read file from console in java 
Java :: java method return list 
Java :: how to use deque as stack in java? 
Java :: java insert char in string at index 
Java :: how to print an array in java 
Java :: method returns arraylist java 
Java :: running sum of 1d array 
Java :: reverse a integer in java 
Java :: array to list java 
Java :: print java 
Java :: double.parsedouble in java 
Java :: radio button java swing 
Java :: how to get child from layout in android 
Java :: java quick sort 
Java :: code for checking android build version 
Java :: fill two dimensional array 
Java :: java convert date to localdate 
Java :: testing the web layer without authentication spring 
Java :: volley library 
Java :: docker java image 
Java :: glide library in android studio 
Java :: java write in a file without overwriting 
Java :: java inline conditional 
Java :: loop hash map 
Java :: java iterate hashmap 
Java :: mapping over a list of promises in javaascript 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =