Java Array to String arrayToString(T[] array)

Here you can find the source of arrayToString(T[] array)

Description

Provides a string representation for the given array.

License

Open Source License

Parameter

Parameter Description
array a parameter

Declaration

public static <T> String arrayToString(T[] array) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from w  w  w.j  a v  a 2 s.  c  o m*/
     * Provides a string representation for the given array.
     * @param array
     * @return
     */
    public static <T> String arrayToString(T[] array) {
        return arrayToString(array, "", "", " ");
    }

    /**
     * Provides a string representation for the given array, where the prefix and suffix of the string,
     * as well as the delimited between the array items are given as parameters.
     * @param array
     * @param prefix
     * @param suffix
     * @param delimiter
     * @return
     */
    public static <T> String arrayToString(T[] array, String prefix, String suffix, String delimiter) {
        StringBuilder sb = new StringBuilder();
        sb.append(prefix);
        boolean firstIteration = true;
        for (T t : array) {
            if (firstIteration) {
                firstIteration = false;
            } else {
                sb.append(delimiter);
            }

            sb.append(t);
        }
        sb.append(suffix);

        return sb.toString();
    }
}

Related

  1. arrayToString(String[] values)
  2. ArrayToString(String[] values)
  3. arrayToString(String[] values)
  4. arrayToString(String[] values)
  5. arrayToString(T[] ar)
  6. arrayToString(T[] array)
  7. arrayToString(T[] array)
  8. arrayToString(T[] array)
  9. arrayToString(T[] array)