Android Set Join join(Set strList, String separator)

Here you can find the source of join(Set strList, String separator)

Description

join

License

Apache License

Declaration

public static String join(Set<String> strList, String separator) 

Method Source Code

/**/*from   w  w w. j a  va2 s.  c  o  m*/
 * Copyright 2013 ??????
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{
    public static final String EMPTY = "";
    
    public static String join(String[] strArray, char separator) {
        StringBuilder sb = new StringBuilder();
        if (strArray != null) {
            boolean isFirst = true;
            for (int i = 0; i < strArray.length; i++) {
                if (isFirst) {
                    isFirst = false;
                } else {
                    sb.append(separator);
                }
                if (StringUtil.isEmpty(strArray[i])) {
                    sb.append(EMPTY);
                } else {
                    sb.append(strArray[i]);
                }
            }
        }
        return sb.toString();
    }
    
    public static String join(String[] strArray, String separator) {
        StringBuilder sb = new StringBuilder();
        if (strArray != null) {
            boolean isFirst = true;
            for (int i = 0; i < strArray.length; i++) {
                if (isFirst) {
                    isFirst = false;
                } else {
                    sb.append(separator);
                }
                if (StringUtil.isEmpty(strArray[i])) {
                    sb.append(EMPTY);
                } else {
                    sb.append(strArray[i]);
                }
            }
        }
        return sb.toString();
    }
    
    public static String join(List<String> strList, String separator) {
        StringBuilder sb = new StringBuilder();
        if (strList != null && !strList.isEmpty()) {
            boolean isFirst = true;
            for (String str : strList) {
                if (isFirst) {
                    isFirst = false;
                } else {
                    sb.append(separator);
                }
                if (StringUtil.isEmpty(str)) {
                    sb.append(EMPTY);
                } else {
                    sb.append(str);
                }
            }
        }
        return sb.toString();
    }
    public static String join(Set<String> strList, String separator) {
        StringBuilder sb = new StringBuilder();
        if (strList != null && !strList.isEmpty()) {
            boolean isFirst = true;
            for (String str : strList) {
                if (isFirst) {
                    isFirst = false;
                } else {
                    sb.append(separator);
                }
                if (StringUtil.isEmpty(str)) {
                    sb.append(EMPTY);
                } else {
                    sb.append(str);
                }
            }
        }
        return sb.toString();
    }
    
    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }
}