Java Array to String convertArrayToString(String[] array, String separator)

Here you can find the source of convertArrayToString(String[] array, String separator)

Description

Converts an Array of Strings into a formatted String

License

Open Source License

Parameter

Parameter Description
array the String[] object
separator the designated splitter

Return

a String

Declaration

public static String convertArrayToString(String[] array, String separator) 

Method Source Code

//package com.java2s;
/**//from   w w w  .  ja  va  2 s.c  o  m
 * StringUtils.java is a part of Joystick
 *
 * Copyright (c) 2016 Anand Kumar
 *
 * Joystick is a free software: You can redistribute it or modify it
 * under the terms of the GNU General Public License published by the Free
 * Software Foundation, either version 3 of the license of any later version.
 * 
 * Joystick is distributed in the intent of being useful. However, there
 * is NO WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You can view a copy of the GNU General Public License at 
 * <http://www.gnu.org/licenses/> if you have not received a copy.
 */

public class Main {
    /**
     * Converts an Array of Strings into a formatted String
     * 
     * @param array
     *            the String[] object
     * @param separator
     *            the designated splitter
     * @return a String
     */
    public static String convertArrayToString(String[] array, String separator) {
        StringBuilder sb = new StringBuilder();
        separator = (separator == null || separator.isEmpty()) ? " " : separator;

        for (String str : array) {
            sb.append(str).append(separator);
        }
        return sb.toString().trim();
    }
}

Related

  1. convertArrayToString(Object[] array, String separator)
  2. convertArrayToString(Object[] ig, int count)
  3. convertArrayToString(Object[] objArr)
  4. convertArrayToString(String[] array)
  5. convertArrayToString(String[] array, char seperator)
  6. convertArrayToString(String[] array, String separator)
  7. convertArrayToString(String[] fields, String delimiter)
  8. convertArrayToString(String[] idArray)
  9. convertArrayToString(String[] strArray)