Java Array to String arrayToStringDelimited(final String[] array, final String delimiter)

Here you can find the source of arrayToStringDelimited(final String[] array, final String delimiter)

Description

Array to string delimited.

License

Open Source License

Parameter

Parameter Description
array the array
delimiter the delimiter

Return

the string

Declaration

public static String arrayToStringDelimited(final String[] array, final String delimiter) 

Method Source Code

//package com.java2s;
/*/* w w w.j a  v a  2  s .  co m*/
 * DeviceUtil.java
 * Copyright (c) 2013, EcoFactor, All Rights Reserved.
 *
 * This software is the confidential and proprietary information of EcoFactor
 * ("Confidential Information"). You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you entered into with
 * EcoFactor.
 */

public class Main {
    /**
     * Array to string delimited. This method will convert a String array into a String delimited by
     * <strong>delimiter</strong>. </br>If the String array is NULL or EMPTY, the method returns an
     * empty string.
     * @param array the array
     * @param delimiter the delimiter
     * @return the string
     */
    public static String arrayToStringDelimited(final String[] array, final String delimiter) {

        final StringBuilder buffer = new StringBuilder();
        final int arrayLength = array != null ? array.length : 0;
        for (int i = 0; i < arrayLength - 1; i++) {
            buffer.append(array[i]).append(delimiter);
        }
        buffer.append(arrayLength > 0 ? array[arrayLength - 1] : "");
        return buffer.toString();
    }
}

Related

  1. arrayToString(T[] array)
  2. arrayToString(T[] array, CharSequence start, CharSequence end)
  3. arrayToString(T[] items, String delimiter)
  4. arrayToString2D(String title, String innerTitle, double[][] vect)
  5. arrayToStringArray(boolean[] values)
  6. arrayToStringNullable(String[] a)
  7. arrayToStrings(String[] s, String delimiter)
  8. arrayToStringWithDifferenceOrientedFormat(double[] values, int minDigits)
  9. arrayToStringWithPrefix(T[] array, String splitter, String prefix)