Java Array Join join(String[] array, String separator)

Here you can find the source of join(String[] array, String separator)

Description

join

License

Apache License

Declaration

public static final String join(String[] array, String separator) 

Method Source Code


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

import java.util.Collection;

public class Main {
    public static final String join(String[] array, String separator) {
        StringBuilder sb = new StringBuilder(1024);
        boolean first = true;

        for (String item : array) {
            if (first) {
                first = false;/* w w  w.ja v  a  2  s. c  om*/
            } else {
                sb.append(separator);
            }

            sb.append(item);
        }

        return sb.toString();
    }

    public static final String join(Collection<String> list, String separator) {
        StringBuilder sb = new StringBuilder(1024);
        boolean first = true;

        for (String item : list) {
            if (first) {
                first = false;
            } else {
                sb.append(separator);
            }

            sb.append(item);
        }

        return sb.toString();
    }
}

Related

  1. join(String[] array, String delimiter)
  2. join(String[] array, String delimiter)
  3. join(String[] array, String delimiter)
  4. join(String[] array, String sep)
  5. join(String[] array, String separator)
  6. join(String[] array, String separator)
  7. join(String[] arrayOfString)
  8. join(String[] datalines)
  9. join(String[] elements, String separator)