What is a StringJoiner in Java 8?

StringJoiner is a new class in Java 8 that can be used to create a String. It can construct a sequence of characters separated by a delimiter. It can also optionally add a prefix and suffix to this sequence. We can use this sequence to get a String.

E.g.
The String “[One:Two:Three]” may be constructed as follows:

StringJoiner sj = new StringJoiner(“:”, “[“, “]”);
sj.add(“One”).add(“Two”).add(“Three”);
String desiredString = sj.toString();

Read the full book at www.amazon.com
Posted in Java 8, Java 8 Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*