Check out example codes for "java stack peek". It will help you in understanding the concepts better.

Code Example 1

// Java code to illustrate peek() function 
  
import java.util.*; 
  
public class StackDemo { 
    public static void main(String args[]) 
    { 
        // Creating an empty Stack 
        Stack<String> STACK = new Stack<String>(); 
  
        // Use push() to add elements into the Stack 
        STACK.push("Welcome"); 
  
        // Fetching the element at the head of the Stack 
        System.out.println("The element at the top of the"
                           + " stack is: " + STACK.peek()); 
  
        // Displaying the Stack after the Operation 
        System.out.println("Final Stack: " + STACK); 
    } 
}

Learn ReactJs, React Native from akashmittal.com