java.util.stream.Collectors with EnumSet Stream

You may use toCollection(Supplier):

return ALL_OPTS.stream().filter(a -> (a.ameityId & bitFlag) > 0)
               .collect(Collectors.toCollection(() -> EnumSet.noneOf(Amenities.class)));

The toCollection method receives a lambda which should create an empty collection to store the result. Here we create empty EnumSet using EnumSet.noneOf call. Note that for EnumSet you must always specify (implicitly or explicitly) which enum is this set for.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)