Java String Array Merge merge(String[] str, String sep)

Here you can find the source of merge(String[] str, String sep)

Description

merge

License

Open Source License

Declaration

public static String merge(String[] str, String sep) 

Method Source Code

//package com.java2s;
/**//w  w w  .  j  a v a 2 s  .c o  m
 * Copyright (c) 2005, 2009 IBM Corporation and others.
 * This software is published under the GPL GNU General Public License.
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * Contributors:
 *     <Quatro Group Software Systems inc.>  <OSCAR Team>
 */

public class Main {
    public static String merge(String[] str, String sep) {
        if (str == null || str.length == 0)
            return "";
        StringBuilder sb = new StringBuilder();
        sb.append(str[0]);
        for (int i = 1; i < str.length; i++) {
            sb.append(sep);
            sb.append(str[i]);
        }
        return sb.toString();
    }

    public static String append(String str1, String str2, String sep) {
        if (IsEmpty(str1))
            return str2;
        if (IsEmpty(str2))
            return str1;
        return str1 + sep + str2;
    }

    public static boolean IsEmpty(String pStr) {
        if (pStr == null || pStr.trim().equals("")) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. merge(String[] arr)
  2. merge(String[] mainSelector, String[] base)
  3. merge(String[] pieces, String sep)
  4. merge(String[] src, String delimiter)
  5. merge(T[] arr0, String delimiter)
  6. mergeInts(int[] values, String delimiter)
  7. mergeJoin(String sep, String[] a1, String[] a2)
  8. mergeJoin(String sep, String[] a1, String[] a2)