Java List Join join(List items, String separator)

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

Description

join

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;

import java.util.List;

public class Main {
    public static String join(List<? extends Object> items, String separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < items.size(); i++) {
            if (i > 0) {
                sb.append(separator);/*from   w  w w  .j a  v  a 2 s . c o  m*/
            }
            sb.append(items.get(i).toString());
        }
        return sb.toString();
    }

    public static String join(float[] items, String separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < items.length; i++) {
            if (i > 0) {
                sb.append(separator);
            }
            sb.append(String.format("%.6f", items[i]));
        }
        return sb.toString();
    }

    public static String join(int[] items, String separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < items.length; i++) {
            if (i > 0) {
                sb.append(separator);
            }
            sb.append(String.format("%d", items[i]));
        }
        return sb.toString();
    }
}

Related

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