Here you can find the source of convertArrayToString(String[] array, String separator)
Parameter | Description |
---|---|
array | the String[] object |
separator | the designated splitter |
public static String convertArrayToString(String[] array, String separator)
//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(); } }