Java Array Join join(String[] stringArray, boolean quote, String glue)

Here you can find the source of join(String[] stringArray, boolean quote, String glue)

Description

join

License

Open Source License

Declaration

public static String join(String[] stringArray, boolean quote, String glue) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static String join(List<?> list, boolean quote, String glue) {

        if (glue == null) {
            glue = ",";
        }//from w  ww.j av a  2s.co  m

        String joinedList = "";

        int count = 0;
        for (Object o : list) {
            if (o == null) {
                continue;
            }
            String s = o.toString();
            if (count > 0) {
                joinedList += glue;
            }
            count++;
            joinedList += quote ? quote(s) : s;
        }

        return joinedList;
    }

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

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

    public static String join(String glue, String... strings) {
        List<String> list = new ArrayList<String>();
        for (String s : strings) {
            list.add(s);
        }
        return join(list, false, glue);
    }

    public static String join(String[] stringArray, boolean quote, String glue) {
        return join(Arrays.asList(stringArray), quote, glue);
    }

    public static String join(String[] stringArray) {
        return join(Arrays.asList(stringArray));
    }

    public static String join(String[] stringArray, String glue) {
        return join(Arrays.asList(stringArray), false, glue);
    }

    public static String quote(String s) {
        return isEmpty(s) ? "" : '"' + s + '"';
    }

    public static boolean isEmpty(String s) {
        return s == null || s.isEmpty();
    }
}

Related

  1. join(String[] names, String sep)
  2. join(String[] parts, String separator)
  3. join(String[] sentence, String separator)
  4. join(String[] strArr)
  5. join(String[] strArray, String delimiter)
  6. join(String[] stringArray, String delimiter)
  7. join(String[] stringArray, String delimiterString, boolean joinNullValues)
  8. join(String[] stringArray, String separator)
  9. join(String[] strings)