Java Vector firstElement() MethodLast Updated : 17 Mar 2025 The firstElement() method of Java Vector class is used to get the first element ( at index 0 ) of the vector which is in use. Syntax:Following is the declaration of firstElement() method: Parameter:This method does not accept any parameter. Returns:The firstElement() method returns the first component of the vector which is in use. Exceptions:NoSuchElementException- This method has thrown an exception if the vector has an empty element. Compatibility Version:Java 1.2 and above Example 1:Output: First element of the vector is = 91 Example 2:Output: First color of this vector = White Example 3:Output: Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Vector.firstElement(Vector.java:511) at myPackage.VectorFirstElementExample3.main(VectorFirstElementExample3.java:8) 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