Java Array to Delimited String arrayToCommaDelimitedString(Object[] strings)

Here you can find the source of arrayToCommaDelimitedString(Object[] strings)

Description

Turns this string array in one comma-delimited string.

License

Apache License

Parameter

Parameter Description
strings The array to process.

Return

The new comma-delimited string. An empty string if strings is null .

Declaration

public static String arrayToCommaDelimitedString(Object[] strings) 

Method Source Code

//package com.java2s;
/**/*from  w  w w .jav  a  2  s. co m*/
 * Copyright 2010-2016 Boxfuse GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Turns this string array in one comma-delimited string.
     *
     * @param strings The array to process.
     * @return The new comma-delimited string. An empty string if {@code strings} is {@code null}.
     */
    public static String arrayToCommaDelimitedString(Object[] strings) {
        if (strings == null) {
            return "";
        }

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < strings.length; i++) {
            if (i > 0) {
                builder.append(",");
            }
            builder.append(String.valueOf(strings[i]));
        }
        return builder.toString();
    }
}

Related

  1. arrayAsCommaSeperatedList(String... items)
  2. arrayAsString(final int[] _intArray)
  3. arrayToCommaDelimitedString(Object[] arr)
  4. arrayToCommaDelimitedString(Object[] arr)
  5. arrayToCommaSeparatedString(int[] array)
  6. arrayToCommaString(int[] array)
  7. arrayToCommaString(int[] array)
  8. arrayToDelimitedString(Object[] arr, String delim)