The Java 8 has added a new class StringJoiner to join Strings. The java.util.StringJoiner can be used to join any number of arbitrary String, a list of String, or an array of String in Java. You can choose any delimiter to join String e.g. command, pipe, colon or semi-colon. The StringJoiner class also allow you to specify a prefix and suffix while joining two or more String in Java. In order to join Strings, you first create an instance of StringJoiner class. While creating, you provide the delimiter, a String or character, which will be used between Strings while joining them e.g. you can pass comma as a delimiter to create a comma separated String or pipe to create a pipe delimited String. In this article, you will see some examples of StringJoiner to learn how to join String in Java 8.
Read more »