Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static void removeItemFromCollectionByUsingIteratorRemoveMethod(Collection<String> collection,
            String elementToBeRemoved) {

        Iterator iterator = collection.iterator();

        while (iterator.hasNext()) {
            String element = (String) iterator.next();

            if (element.equals(elementToBeRemoved)) {
                iterator.remove();
            }
        }
    }
}