Java Array to Delimited String arrayToDelimitedString(Object[] arr, String delim)

Here you can find the source of arrayToDelimitedString(Object[] arr, String delim)

Description

Convenience method to return a String array as a delimited (e.g.

License

Apache License

Parameter

Parameter Description
arr array to display. Elements may be of any type (toString() will be called on each element).
delim delimiter to use (probably a ,)

Declaration

public static String arrayToDelimitedString(Object[] arr, String delim) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from   w w  w  .j  a va  2 s.c  o m
     * Convenience method to return a String array as a delimited (e.g. CSV)
     * String. Useful for toString() implementations
     * @param arr array to display. Elements may be of any type (toString() will be
     * called on each element).
     * @param delim delimiter to use (probably a ,)
     */
    public static String arrayToDelimitedString(Object[] arr, String delim) {
        if (arr == null)
            return "null";
        else {
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < arr.length; i++) {
                if (i > 0)
                    sb.append(delim);
                sb.append(arr[i]);
            }
            return sb.toString();
        }
    }
}

Related

  1. arrayToCommaDelimitedString(Object[] strings)
  2. arrayToCommaSeparatedString(int[] array)
  3. arrayToCommaString(int[] array)
  4. arrayToCommaString(int[] array)
  5. arrayToDelimitedString(Object[] arr, String delim)
  6. arrayToDelimitedString(Object[] arr, String delim)
  7. arrayToDelimitedString(String[] values, String delimiter)
  8. arrayToDelimitedString(T[] array, String left, String delimiter, String right)
  9. arrayToReadableString(String[] array)