StringJoiner is used to construct a sequence of characters separated by a delimiter and optionally starting with a supplied prefix and ending with a supplied suffix.
Java StringJoiner Example
The following example joins numbers with the StringJoiner class.
import java.util.StringJoiner;
public class StringJoinerDemo {
public static void main(String[] args) {
StringJoiner join = new StringJoiner(",");
join.add("1");
join.add("2");
join.add("3");
join.add("4");
join.add("5");
join.add("6");
System.out.println(join);
}
}
Output:
1,2,3,4,5,6
Reference
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course