Android String Array Join join(String[] array, String separator, boolean ignoreNull)

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

Description

join

License

Apache License

Declaration

public static String join(String[] array, String separator,
            boolean ignoreNull) 

Method Source Code

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

import java.util.Arrays;

import java.util.List;

public class Main {
    public static String join(List<String> list, String separator,
            boolean ignoreNull) {
        if (list.isEmpty())
            return "";

        StringBuilder b = new StringBuilder();
        for (String item : list) {
            if (!ignoreNull || item != null) {
                b.append(separator).append(item);
            }/* ww  w.  j ava 2  s .c om*/
        }

        if (b.length() == 0) {
            return "";
        }

        return b.toString().substring(separator.length());
    }

    public static String join(List<String> list, String separator) {
        return join(list, separator, false);
    }

    public static String join(String[] array, String separator,
            boolean ignoreNull) {
        return join(Arrays.asList(array), separator, ignoreNull);
    }

    public static String join(String[] array, String separator) {
        return join(array, separator, false);
    }
}

Related

  1. join(String[] strArray, String separator)
  2. join(String[] array, String separator)
  3. arrayToStr(String[] array)
  4. arrayToStr(String[] array, String delim)
  5. implode(String[] array)
  6. join(String[] list, String sep)
  7. toString(String[] arr, String delimiter)
  8. join(String[] strArray, char separator)