Get All Enum Values To A List
Using of EnumSet
is other way:
List<String> fruits = EnumSet.allOf(FruitsEnum.class)
.stream()
.map(FruitsEnum::getValue)
.collect(Collectors.toList());
This should do the trick:
Arrays.stream(FruitsEnum.values())
.map(FruitsEnum::getValue)
.collect(Collectors.toList());
You need to map
with getValue
List<String> fruits = Stream.of(FruitsEnum.values())
.map(FruitsEnum::getValue) // map using 'getValue'
.collect(Collectors.toList());
System.out.println(fruits);
this will give you the output
[APPL, BNN]