filter a List from a String Array - Java java.util

Java examples for java.util:List Operation

Description

filter a List from a String Array

Demo Code


//package com.java2s;

import java.util.List;

public class Main {
    public static void main(String[] argv) {
        String[] strs = new String[] { "1", "abc", "level", null,
                "java2s.com", "asdf 123" };
        List list = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(filter(strs, list));
    }//from   w w w  .ja va2  s  .  c  o  m

    public static List filter(String[] strs, List list) {
        for (int i = 0; i < strs.length; i++) {
            while (list.contains(strs[i]))
                list.remove(strs[i]);
        }
        return list;
    }
}

Related Tutorials