Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
ArrayDeque peekLast() Method in Java
Next article icon

ArrayDeque peekLast() Method in Java

Last Updated : 10 Dec, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The java.util.ArrayDeque.peekLast() method in Java is used to retrieve or fetch the last element of the deque. The element retrieved does not get deleted or removed from the Queue instead the method just returns it. If no element is present in the deque or it is empty, then Null is returned. Syntax:
Array_Deque.peekLast()
Parameters: The method does not take any parameter. Return Value: The method returns the last element of the Deque. Below programs illustrate the Java.util.ArrayDeque.peekLast() method: Program 1: Java
// Java code to illustrate peekLast() import java.util.*;  public class ArrayDequeDemo {     public static void main(String args[])     {         // Creating an empty ArrayDeque         Deque<String> de_que = new ArrayDeque<String>();          // Use add() method to add elements into the Deque         de_que.add("Welcome");         de_que.add("To");         de_que.add("Geeks");         de_que.add("4");         de_que.add("Geeks");          // Displaying the ArrayDeque         System.out.println("Initial ArrayDeque: " + de_que);          // Displaying the last element         System.out.println("The last element is: " +                                             de_que.peekLast());          // Displaying the ArrayDeque after operation         System.out.println("Final ArrayDeque: " + de_que);     } } 
Output:
  Initial ArrayDeque: [Welcome, To, Geeks, 4, Geeks]  The last element is: Geeks  Final ArrayDeque: [Welcome, To, Geeks, 4, Geeks]  
Program 2: Java
// Java code to illustrate peekLast() import java.util.*;  public class ArrayDequeDemo {     public static void main(String args[])     {         // Creating an empty ArrayDeque         Deque<Integer> de_que = new ArrayDeque<Integer>();          // Use add() method to add elements into the Deque         de_que.add(10);         de_que.add(15);         de_que.add(30);         de_que.add(20);         de_que.add(5);          // Displaying the ArrayDeque         System.out.println("Initial ArrayDeque: " + de_que);          // Displaying the last element         System.out.println("The last element is: " +                                             de_que.peekLast());          // Displaying the ArrayDeque after operation         System.out.println("Final ArrayDeque: " + de_que);     } } 
Output:
  Initial ArrayDeque: [10, 15, 30, 20, 5]  The last element is: 5  Final ArrayDeque: [10, 15, 30, 20, 5]  
Program 3: For an empty deque: Java
// Java code to illustrate peekLast() import java.util.*;  public class ArrayDequeDemo {     public static void main(String args[])     {         // Creating an empty ArrayDeque         ArrayDeque<Integer> de_que = new ArrayDeque<Integer>();          // Displaying the ArrayDeque         System.out.println("ArrayDeque: " + de_que);          // Displaying the last element         System.out.println("The last element is: " + de_que.peekLast());     } } 
Output:
  ArrayDeque: []  The last element is: null  

Next Article
ArrayDeque peekLast() Method in Java

C

chinmoy lenka
Improve
Article Tags :
  • Misc
  • Java
  • Java-Collections
  • Java - util package
  • Java-Functions
  • Java-ArrayDeque
Practice Tags :
  • Java
  • Java-Collections
  • Misc

Similar Reads

    ArrayDeque contains() Method in Java
    The Java.util.ArrayDeque.contains() method in Java is used to check or verify whether a specific element is present in the Deque or not. Syntax: Array_Deque.contains(Object element) Parameters: The parameter element is of the type of ArrayDeque. This is the element that needs to be tested if it is p
    2 min read
    ArrayDeque iterator() Method in Java
    The Java.util.ArrayDeque.iterator() method is used to return an iterator of the elements of the ArrayDeque. Syntax: Iterator iterate_value = Array_Deque.iterator(); Parameters: The method does not take any parameter. Return Value: The method iterates over the elements of the deque and returns the va
    2 min read
    ArrayDeque descendingIterator() Method in Java
    The Java.util.ArrayDeque.descendingIterator() method is used to return an iterator of the same elements as the ArrayDeque but in the reverse order. Syntax: Iterator iterate_value = Array_Deque.descendingIterator(); Parameters: The method does not take any parameter. Return Value: The method iterates
    2 min read
    ArrayDeque element() Method in Java
    The java.util.ArrayDeque.element() method in Java is used to retrieve or fetch the head of the ArrayDeque. In the process, the method does not delete the element from the deque instead it just returns the element. Syntax: Array_Deque.element() Parameters: The method does not take any parameter. Retu
    2 min read
    ArrayDeque getFirst() Method in Java
    The java.util.ArrayDeque.getFirst() method in Java is used to retrieve or fetch the first element of the ArrayDeque. In the process, the method does not delete the element from the deque instead it just returns the first element of the deque. Syntax: Array_Deque.getFirst() Parameters: The method doe
    2 min read
    ArrayDeque getLast() Method in Java
    The java.util.ArrayDeque.getLast() method in Java is used to retrieve or fetch the last element of the ArrayDeque. In the process, the method does not delete the element from the deque instead it just returns the last element of the deque.Syntax: Array_Deque.getLast() Parameters: The method does not
    2 min read
    ArrayDeque isEmpty() Method in Java
    The Java.util.ArrayDeque.isEmpty() method in Java is used to check and verify if an ArrayDeque is empty or not. It returns True if the Deque is empty else it returns False. Syntax: Array_Deque.isEmpty() Parameters: The method does not take any parameter. Return Value: The function returns True if th
    2 min read
    ArrayDeque toArray() Method in Java
    The java.util.ArrayDeque.toArray() method is used to form an array of the same elements as that of the Deque. Basically, the method copies all the element from this deque to a new array. Syntax: Object[] arr = Array_Deque.toArray() Parameters: The method does not take any parameters. Return Value: T
    2 min read
    ArrayDeque offer() Method in Java
    The Java.util.ArrayDeque.offer(Object element) method in Java is used to add a specific element at the end of the Deque. The function is similar to the offerLast() method of ArrayDeque in Java. Syntax: Array_Deque.offer(Object element) Parameters: The parameter element is of the type ArrayDeque and
    2 min read
    ArrayDeque offerFirst() Method in Java
    The Java.util.ArrayDeque.offerFirst(Object element) method in Java is used to add a specific element at the front of the Deque. The function is similar to the addFirst() method of ArrayDeque in Java. Syntax: Array_Deque.offerFirst(Object element) Parameters: The parameter element is of the type Arra
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences