Java Array Join join(String[] stringArray, String delimiterString, boolean joinNullValues)

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

Description

join

License

Open Source License

Declaration

public static String join(String[] stringArray, String delimiterString, boolean joinNullValues) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static String join(String[] stringArray, String delimiterString, boolean joinNullValues) {
        List<String> list = new ArrayList<String>();
        for (int i = 0; stringArray != null && i < stringArray.length; i++) {
            list.add(stringArray[i]);//from   w ww .j  a  v  a2 s.c  om
        }
        return join(list, delimiterString, joinNullValues);
    }

    public static String join(List<String> stringList, String delimiterString, boolean joinNullValues) {
        String retStr = "";
        for (int i = 0; stringList != null && i < stringList.size(); i++) {
            String stringElem = null;
            if (stringList.get(i) != null)
                retStr += stringList.get(i);
            if (i < stringList.size() - 1) {
                if (joinNullValues && stringElem == null)
                    retStr += delimiterString;
                else if (stringElem != null)
                    retStr += delimiterString;
            }
        }
        return retStr;
    }
}

Related

  1. join(String[] sentence, String separator)
  2. join(String[] strArr)
  3. join(String[] strArray, String delimiter)
  4. join(String[] stringArray, boolean quote, String glue)
  5. join(String[] stringArray, String delimiter)
  6. join(String[] stringArray, String separator)
  7. join(String[] strings)
  8. join(String[] strings, char delimiter)
  9. join(String[] strings, char delimiter)