Java Vector firstElement() MethodThe 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:Test it NowOutput: First element of the vector is = 91 Example 2:Test it NowOutput: First color of this vector = White Example 3:Test it NowOutput: 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 provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India