Convert a List<String> to a Set with Java 8

Viewed 6632

Is there a one-liner to convert a list of String to a set of enum? For instance, having:

public enum MyVal {
    ONE, TWO, THREE
}

and

List<String> myValues = Arrays.asList("ONE", "TWO", "TWO");

I'd like to convert myValues to a Set<MyVal> containing the same items as:

EnumSet.of(MyVal.ONE, MyVal.TWO)
2 Answers
Related