Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Java peek() Method

import java.util.Stack;

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

        // Add elements to Stack
        animals.push("Dog");
        animals.push("Horse");
        animals.push("Cat");
        System.out.println("Stack: " + animals);

        // Access element from the top
        String element = animals.peek();
        System.out.println("Element at top: " + element);

    }
}
Comment

peek method

  peek() {
    return this.elements[this.head];
  }


//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
Comment

PREVIOUS NEXT
Code Example
Java :: garbage collection in java 
Java :: how to get ascii value of string letter in java 
Java :: check if short int or long java 
Java :: User input (scanner) 
Java :: arrays with for loops 
Java :: javax dependency android 
Java :: priority queue java 
Java :: encode file to utf-8 in java 
Java :: string to char array 
Java :: java boolean data type 
Java :: java stream index 
Java :: spring boot send api request 
Java :: fill array with random numbers 
Java :: interface vs abstract class java 
Java :: how to use java 
Java :: java startswith regex 
Java :: how to set default focus on edittext in android 
Java :: java first index of an arraylist 
Java :: spring boot prerequisites 
Java :: why string is immutable in java 
Java :: wrapper classes in java ebhor.com 
Java :: how to use another class in java inside of an action listenrer 
Java :: java loop find index 
Java :: how to change state of a Switch programmatically andoir dstudio 
Java :: add element to arraylist of arraylist java 
Java :: java gui bank account program 
Java :: Deque interface in Java 
Java :: int in double umwandeln java 
Java :: jframe centerlaized 
Java :: viewresolver in spring boot 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =