I have a List of Enum values like MON, TUE, WED, etc., same need to convert to comma-separated String. Need to use Java 8 to convert the same in an efficient way. For example.
Arrays.stream(Days.values())
.map(MON -> TimeRangeConstants.MON)
.collect(Collectors.joining(","));
enum Days {
MON, TUE, WED, THU, FRI, SAT, SUN;
}
main() {
Days v1 = Days.MON;
Days v2 = Days.WED;
Days v3 = Days.FRI;
List<Days> days = new ArrayList<>();
days.add(v1);
days.add(v2);
days.add(v3);
String str = convertToString(days);
}
convertToString(List<Days> list) {
// need to return String as "Monday, Wednesday, Friday"
}
For the given above example, I need output as "Monday, Wednesday, Friday"
DayOfWeekenum that already exists in the standard API?