minus one List from another List - Java java.util

Java examples for java.util:List Operation

Description

minus one List from another List

Demo Code


//package com.java2s;
import java.util.*;

public class Main {
    public static void main(String[] argv) {
        List initialList = java.util.Arrays.asList("asdf", "java2s.com");
        List elementsToRemove = java.util.Arrays.asList("asdf",
                "java2s.com");
        System.out.println(minus(initialList, elementsToRemove));
    }/* www  .  java  2  s . co  m*/

    public static <T> List<T> minus(List<T> initialList,
            List<T> elementsToRemove) {
        List<T> minusedList = new ArrayList<T>(initialList);
        minusedList.removeAll(elementsToRemove);
        return minusedList;
    }
}

Related Tutorials