So it's Collector / Collectors. It seems to be used when you want to extract the result of Stream while processing it. Below is a sample.
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
*Studying Collectors
* @author komikcomik
*
*/
public class CollectorsHello {
public static void main(String[] args) {
//The stream of the character string is combined into a String, and the delimiter, the first character, and the last character are added at that time.
Stream<String> s = Stream.of("1", "2", "3", "4", "5", "6", "7");
String ss = s.collect(Collectors.joining("-", "lead", "end"));
System.out.println(ss);
}
}
The execution result is as follows.
First 1-2-3-4-5-6-7 end
Recommended Posts