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.List;

public class Main {
    public static <T> boolean retainAllByValue(Collection<T> c1, Collection<? extends T> c2) {
        if (c1 == null || c2 == null || c1.isEmpty() || c2.isEmpty())
            return false;
        List<T> itemsToRemove = new ArrayList<T>();
        for (T item : c1) {
            if (!containsByValue(c2, item))
                itemsToRemove.add(item);
        }
        c1.removeAll(itemsToRemove);
        return (!itemsToRemove.isEmpty());
    }

    public static <T> boolean containsByValue(Collection<? extends T> c, T item) {
        if (c == null || c.isEmpty())
            return false;
        for (T i : c) {
            if (i.equals(item))
                return true;
        }
        return false;
    }
}