Best way to use Java8 streams to implement this collection

Viewed 60
private enum EnumVals {
        FIRST(new String[]{"a","b"}),
        SECOND(new String[]{"a","b","c","d"}),
          THIRD(new String[]{"d","e"});

        private String[] vals;

        EnumVals(String[] q) {
            vals=q;
        }

        public String[] getValues(){
            return vals;
        }
    };

What I need is the unique combined list of all EnumVals.getValues().

String[] allVals = {"a","b","c","d","e"}

I did something like below, but it throws error :

Stream.of(EnumVals.values()).map(w->w.getValues()).collect(Collectors.toCollection(HashSet::new)).toArray(new String[0]);
1 Answers
Related