Stream.of("1","2","3","4")这个是输入我想得到1,2,3,4的输出,怎么写?
欢迎选择我的课程,让我们一起见证您的进步~~
Use reduce
Stream.of("1","2","3","4").reduce((a,b) -> a +"," +b))
If you are like me and don’t understand what reduce does
String.join(",", stringStream.collect(Collectors.toList()));
It’s a bit difficult to change your thinking
Stream.of(1, 2, 3, 4).reduce(new StringBuilder(), (sb, s) -> sb.append(s).append(','), StringBuilder::append).toString();
Use reduce
If you are like me and don’t understand what reduce does
It’s a bit difficult to change your thinking