Java ListIterator set() MethodLast Updated : 17 Mar 2025 The set() method of ListIterator interface is used to replace the last element which is returned by the next() or previous() along with the given element. The call can be added only if neither remove() nor add(E) method have been called. SyntaxParametersThe above method requires only one parameter:
ReturnNA Throws:UnsupportedOperationException- If the given set operation is not supported by the list iterator. ClassCastException- If the given class of the specified element is not supported by the list iterator. IllegalArgumentException- If some of the aspects of the given element avoid it from being added to the list. IllegalStateException- If neither the next() nor the previous() method has been called. Example 1Output: The list of the names of the students is given as: [Ravi, Tina, Payal, Aashi] Before using the set() method : Ravi Tina Payal Aashi After using the set() method : Ravi Tina Payal None Example 2Output: The list of marks of the students is given as: [44.7, 67.0, 78.0, 98.9] Before using the set() method : 44.7 67.0 78.0 98.9 After using the set() method : 44.7 67.0 78.0 12.4 Example 3Output: The list of age of the students is given as: [23, 56, 34, 98] Before using the set() method : 23 56 34 98 After using the set() method : 23 56 34 12 Next TopicJava ListIterator |
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