среда, 7 ноября 2012 г.

[JAVA] Аналог PHP функции implode для String collection

Такая полезная функция как implode отсутствует в java.
Исправим:

import org.apache.commons.lang.StringUtils;

public static String implodeArray(String[] inputArray, String glueString) {

    /** Output variable */
    String output = "";
    output = StringUtils.join( inputArray, glueString );
    return output;
} 

Вот какие типы можно вообще в join использовать:
static Stringjoin(Collection collection, char separator) 
          Joins the elements of the provided Collection into a single String containing the provided elements.
static Stringjoin(Collection collection, String separator) 
          Joins the elements of the provided Collection into a single String containing the provided elements.
static Stringjoin(Iterator iterator, char separator) 
          Joins the elements of the provided Iterator into a single String containing the provided elements.
static Stringjoin(Iterator iterator, String separator) 
          Joins the elements of the provided Iterator into a single String containing the provided elements.
static Stringjoin(Object[] array) 
          Joins the elements of the provided array into a single String containing the provided list of elements.
static Stringjoin(Object[] array, char separator) 
          Joins the elements of the provided array into a single String containing the provided list of elements.
static Stringjoin(Object[] array, char separator, int startIndex, int endIndex) 
          Joins the elements of the provided array into a single String containing the provided list of elements.
static Stringjoin(Object[] array, String separator) 
          Joins the elements of the provided array into a single String containing the provided list of elements.
static Stringjoin(Object[] array, String separator, int startIndex, int endIndex) 
          Joins the elements of the provided array into a single String containing the provided list of elements.
Полное описание класса StringUtils


Комментариев нет:

Отправить комментарий