Added List.joining(delim, prefix, suffix) convenience method

This commit is contained in:
Reinhard Pointner 2016-10-08 23:13:07 +08:00
parent 845dc26c83
commit db85b77dad
1 changed files with 8 additions and 0 deletions

View File

@ -374,6 +374,14 @@ public class ExpressionFormatMethods {
return self; return self;
} }
public static String joining(List<?> self, String delimiter, String prefix, String suffix) {
String[] list = self.stream().filter(Objects::nonNull).map(Objects::toString).filter(s -> !s.isEmpty()).toArray(String[]::new);
if (list.length == 0) {
return null;
}
return prefix + String.join(delimiter, list) + suffix;
}
/** /**
* Unwind if an object does not satisfy the given predicate * Unwind if an object does not satisfy the given predicate
* *