Can we remove elements from ArrayList while iterating?
Ngày đăng:
01/01/2022
Trả lời:
0
Lượt xem:
170
Use Iterator to remove an element from a Collection in JavaJava 8Object Oriented ProgrammingProgramming An element can be removed from a Collection using the Iterator method remove(). This method removes the current element in the Collection. If the remove() method is not preceded by the next() method, then the exception IllegalStateException is thrown. A program that demonstrates this is given as follows. ExampleLive Demo OutputThe output of the above program is as follows The ArrayList elements are: Apple Mango Guava Orange Peach The element Orange is removed The ArrayList elements are: Apple Mango Guava PeachArjun Thakur Published on 18-Jan-2019 06:08:12 Previous Page Print Page Next Page Advertisements |