Java Vector lastElement() MethodThe 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 1Test it NowOutput: The last element of a vector is: Python Example 2Test it NowOutput: Element of a vector is: [11, 22, 33, 44] The last element of a vector is: 44 Example 3Test it NowOutput: 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 provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India