Removes one instance of the specified object from this Collection if one is contained (optional). This implementation iterates over this Collection and tests for each element e returned by the iterator, whether e is equal to the given object. If object != null
(Object object)
| 223 | * doesn't support {@code null} elements. |
| 224 | */ |
| 225 | public boolean remove(Object object) { |
| 226 | Iterator<?> it = iterator(); |
| 227 | if (object != null) { |
| 228 | while (it.hasNext()) { |
| 229 | if (object.equals(it.next())) { |
| 230 | it.remove(); |
| 231 | return true; |
| 232 | } |
| 233 | } |
| 234 | } else { |
| 235 | while (it.hasNext()) { |
| 236 | if (it.next() == null) { |
| 237 | it.remove(); |
| 238 | return true; |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | return false; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Removes all occurrences in this {@code Collection} of each object in the |