Welcome Board Line with joining()
A school entrance board wants to display guest names on one line instead of printing each name separately. The names should appear in their original order, separated by " | ".
Your task is to return one combined string built from the list of names. If the list is empty, the answer should be an empty string.
For example, if the input is ["Ayu", "Bima", "Cici"], the result should be "Ayu | Bima | Cici". If the input is ["Dino"], the result should simply be "Dino".
This challenge focuses on the joining() collector in a Java stream. The goal is not to transform or remove names, but to combine them into one readable output line.
Example Input & Output
A one-name list produces a one-name string without extra separators.
An empty list returns an empty string.
The names are combined into one line with the required separator.
Algorithm Flow

Solution Approach
This problem is a very natural use case for Collectors.joining(). Instead of building the result manually with loops and separators, Java can collect the stream elements into one string in a single step.
The separator here is fixed: " | ". That means the stream pipeline can stay short and clear:
This works because the collector handles the separator placement for you. There is no extra trailing delimiter, and a one-item list stays as just that one name. An empty list naturally becomes an empty string.
The runtime is O(n) in the number of names and characters processed, and the code reads very closely to the problem statement: stream the names and join them with the given separator.
Best Answers
import java.util.List;
import java.util.stream.Collectors;
class Solution {
public static String buildWelcomeBoard(List<String> names) {
return names.stream()
.map(String::trim)
.collect(Collectors.joining(" | "));
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
