- joining operation on Collectors provides a way to aggregate the result of a stream operation into a concatenated string.
- There are two implementations. The first simply concatenates the stream items, while the second concatenates the items with a delimiter.
stream of employees
Stream employees = Stream.of(
new Employee("Joe", "Blogs", "Sales", 100.0),
new Employee("Richardo", "Banks", "Engineering", 50.0),
new Employee("Hewlet", "Packer", "Marketing",40.0)
);
another stream of employees
USAGE
collecting stream of transformation result in a concatenated string
Stream employees_2 = Stream.of(
new Employee("Ruben", "Paul", "Sales", 100.0),
new Employee("Shelly", "Smith", "Engineering", 50.0)
);
USAGE
collecting stream of transformation result in a concatenated string
String LastNames = employees
.map(employee -> employee.getLastName())
.collect(Collectors.joining());
collecting stream of transformation result in a comma-separated string
String LastNamesCommaSeparated = employees_2
.map(employee -> employee.getLastName())
.collect(Collectors.joining(", "));
Comments
Post a comment