The Collectors.joining() function helps you join elements of a Stream, containing strings. It has three optional parameters, namely—delimiter, prefix, and postfix.
Consider the following example of the program:
fun main(args: Array<String>) { val resultantString = Stream.builder<String>() .add("Item 1") .add("Item 2") .add("Item 3") .add("Item 4") .add("Item 5") .add("Item 6") .build() .collect(Collectors.joining(" - ","Starts Here=>","<=Ends Here")) println("resultantString $resultantString") }
The output is as follows: