Java List Join join(List items, String conjunction)

Here you can find the source of join(List items, String conjunction)

Description

String.join is available only with Java 1.8.

License

Apache License

Declaration

static public String join(List<? extends Object> items, String conjunction) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.List;

public class Main {
    /** String.join is available only with Java 1.8. We support 1.7.
     *//from  w ww  .  j  a v a  2s. co m
     *  Format a list of items as strings, separated by the given conjunction.
     */
    static public String join(List<? extends Object> items, String conjunction) {
        StringBuilder sb = new StringBuilder();
        boolean first = true;
        for (Object x : items) {
            if (first) {
                first = false;
            } else {
                sb.append(conjunction);
            }
            if (x == null) {
                sb.append("<null>");
            } else {
                sb.append(x.toString());
            }
        }
        return sb.toString();
    }
}

Related

  1. join(List strings, String delimiter)
  2. join(List vec, String separator)
  3. join(List items, CharSequence delimiter)
  4. join(List s, String delimiter)
  5. join(List s, String delimiter)
  6. join(List items, String separator)
  7. join(List list)
  8. join(List olist, String glue)
  9. join(List valueList, String separator)