Java8-Streamjoin
/**
* ⽣成连接字符串
* join("_", 1)        => 1
* join("_", 1, 2)    => 1_2
* join("_", 1, 2, 3)  => 1_2_3
* @param delimiter
* @param objects
* @return
*/
public static String join(String delimiter, objects) {
Stream.Builder<String> keyStreamBuilder = Stream.builder();
Arrays.stream(objects).map(o -> {
if (o instanceof String) {
return (String) o;
} else {
return String.valueOf(o);
}
}).forEach(keyStreamBuilder::add);
return keyStreamBuilder.build().collect(Collectors.joining(delimiter));
}
>java stream

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。