I want to get either empty list or list of strings from CSV. And I tried below approach:
String valueStr = "US,UK";
List<String> countryCodes = StringUtils.isBlank(valueStr)
? Collections.emptyList()
: Arrays.stream(valueStr.split(DELIMITER))
.map(String::trim)
.collect(Collectors.toList());
How can I make it more concise without ternary operator, keeping it easy as well? This works fine. Just checking other approaches.
Optional.ofNullable(valueStr) .map(s->Arrays.stream(s.split(DELIMITER)) .map(String::trim) .collect(Collectors.toList())).orElse(Collections.emptyList());