Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class Main {
    public static List<String> removeItemFromCollectionByReturningNewList(Collection<String> collection,
            String elementToBeRemoved) {

        Iterator iterator = collection.iterator();

        List<String> filteredCollection = new ArrayList<>();

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

            if (!element.equals(elementToBeRemoved)) {
                filteredCollection.add(element);
            }
        }

        return filteredCollection;
    }
}