Java Vector forEach() MethodLast Updated : 17 Mar 2025 The forEach() method of Java Vector class is used to perform the given action for each element of the Iterable until all elements have been processed or the action throws an exception. Actions are performed in the order of iteration if that order is specified. Syntax:Following is the declaration of forEach() method: Parameter:
Returns:The forEach() method does not return anything. It only performs the given action for each element. Exceptions:NullPointerException- This method has thrown an exception if the specified action is null. Compatibility Version:Java 1.2 and above Example 1:Output: 1 2 3 4 5 Example 2:Output: White Green Black Pink 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