Java Vector lastElement() MethodLast Updated : 17 Mar 2025 The lastElement() method of Java Vector class is used to get the last component of the vector. SyntaxFollowing is the declaration of lastElement() method: ParameterThis method does not accept any parameter. ReturnThe lastElement() method returns the last element of the vector i.e. the component at index size()-1. ExceptionsNoSuchElementException- This method has thrown an exception if the vector is empty. Compatibility VersionJava 1.2 and above Example 1Output: The last element of a vector is: Python Example 2Output: Element of a vector is: [11, 22, 33, 44] The last element of a vector is: 44 Example 3Output: The last element of a vector is: 404 Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Vector.lastElement(Vector.java:525) at myPackage.VectorLastElementExample3.main(VectorLastElementExample3.java:17) Next TopicJava Vector |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India