Java Utililty Methods StringJoiner Usage

List of utility methods to do StringJoiner Usage

Description

The list of methods to do StringJoiner Usage are organized into topic(s).

Method

StringjoinRepeating(String element, String delimiter, int times)
join Repeating
StringJoiner joiner = new StringJoiner(delimiter);
for (int i = 0; i < times; ++i) {
    joiner.add(element);
return joiner.toString();
StringjoinToString(String sep, Iterable items)
join To String
final StringJoiner j = new StringJoiner(sep);
items.forEach(j::add);
return j.toString();
StringlistToString(List list)
list To String
if (list == null || list.isEmpty())
    return null;
StringJoiner joiner = new StringJoiner(",", "[", "]");
for (Object o : list) {
    if (o == null)
        joiner.add("null");
    else
        joiner.add(o.toString());
...
voidprint(int[] a)
print
StringJoiner sj = new StringJoiner(",", "[", "]");
for (int i = 0; i < a.length; i++) {
    sj.add(String.valueOf(a[i]));
System.out.println(sj.toString());
Stringsplit(String s)
split
if (s == null || s.isEmpty()) {
    return s;
StringJoiner joiner = new StringJoiner(" ");
for (String word : s.split(RE_CAMELCASE_OR_UNDERSCORE)) {
    if (!word.isEmpty()) {
        joiner.add(word.trim());
return joiner.toString();
voidthrowSafeguardError(String thisClassName, String thisMethodsName, String superClassName, String... namesOfMethodsWhoseDefaultImplementationUsesThisMethod)
A utility method throwing an error to indicate that a method used by a default implementation of another method has not been overridden.
String oneOf = namesOfMethodsWhoseDefaultImplementationUsesThisMethod.length > 1 ? "one of " : "";
throw new Error(thisMethodsName + " is being invoked but has not been overridden by " + thisClassName + ". "
        + "It is probably being invoked by the default implementation of " + oneOf
        + join(namesOfMethodsWhoseDefaultImplementationUsesThisMethod) + " in " + superClassName
        + ", unless some other overriding method invokes it. " + "If the default implementation of "
        + join(namesOfMethodsWhoseDefaultImplementationUsesThisMethod) + " in " + superClassName
        + " is being used, " + thisMethodsName + " should be overridden," + " or if " + thisMethodsName
        + " does not make sense for " + thisClassName
...
StringtoCVS(Set buildRecordSetIds)
to CVS
StringJoiner joiner = new StringJoiner(",");
buildRecordSetIds.forEach(el -> joiner.add(el.toString()));
return joiner.toString();