Aug 23, 2017

Java 8 offers static methods join as part of the String class definition.

The join method offers the convenience of not adding the delimiter at the end of the string as well. As a matter of fact, class String offers two join methods with the following signatures:

public static String join(CharSequence delimiter, CharSequence... elements)

public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements)

The method's contract doesn't allow the parameters to be passed as null. If the contract is violated, i.e. if one or both the parameters are null, then the method will throw a NullPointerException.


String.join("; ", myList);
Post a Comment

Featured Post

Trading volumes of most major cryptocurrencies across leading exchanges remain low overall

Bitcoin's daily trading volume has been relatively low