How to stream value of Java List (Varargs) in a method?

Jack :

I have the following method:

public static List<A> getValuesExclusion(A exclusion) {
        return Arrays.stream(values())
                .filter(item -> item != exclusion)
                .collect(Collectors.toList());
}
//this function returns enum list of A types that has no A type'exclusion'

Now I want to make it into a list as argument:

public static List<A> getValuesExclusion(A... exclusions){
        return Arrays.stream(values())
                .filter(???)
                .collect(Collectors.toList());
}

My question is, how can I do the filter for the second case? I would like to retrieve an enum list that excludes all the values "exclusions" as input. Here are the attributes of class A:

public enum A implements multilingualA{
    A("a"),
    B("b"),
    C("c"),
    D("d");
    ...
}
GBlodgett :

If you want to make sure all the items are not included in the exclusions you could do:

public static List<A> getValuesExclusion(AType... exclusions){
        return Arrays.stream(values())
                .filter(e -> Arrays.stream(exclusions).noneMatch(c -> c == e))
                .collect(Collectors.toList());
}

Which will create a Stream of exclusions and then use noneMatch() to ensure the given AType is not included in the Array

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=72594&siteId=1