Java ListIterator set() MethodThe 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 1Test it NowOutput: 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 2Test it NowOutput: 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 3Test it NowOutput: 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 provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India