Here you can find the source of toString(T[] array, String prefix, String sep, String suffix)
Parameter | Description |
---|---|
T | The type of array elements. |
array | An array of elements. It may be null. |
prefix | String to be used as prefix. |
sep | String to be used to separate array elements. |
suffix | String to be used as suffix. |
public static <T> String toString(T[] array, String prefix, String sep, String suffix)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; import java.util.Collection; public class Main { /**//from w w w. j a va 2s . c o m * Provides a string representation of the elements in the given collection. * * @param c A collection of elements. It may be null. * @param prefix String to be used as prefix. * @param sep String to be used to separate elements in the collection. * @param suffix String to be used as suffix. * @param <T> The type of elements in the collection. * * @return String representation of the elements in the collection. */ public static <T> String toString(Collection<T> c, String prefix, String sep, String suffix) { if (c == null || c.size() == 0) return prefix + suffix; Iterator<T> it = c.iterator(); String result = prefix + it.next(); while (it.hasNext()) result += sep + it.next(); return result + suffix; } public static <T> String toString(final Collection<T> a) { return toString(a, "", ",", ""); } /** * Provides a string representation of the elements in the given array. * * @param <T> The type of array elements. * @param array An array of elements. It may be null. * @param prefix String to be used as prefix. * @param sep String to be used to separate array elements. * @param suffix String to be used as suffix. * * @return String representation of the elements in the array. */ public static <T> String toString(T[] array, String prefix, String sep, String suffix) { if (array == null || array.length == 0) return prefix + suffix; String result = prefix + array[0]; for (int i = 1; i < array.length; i++) { result += sep + array[i]; } return result + suffix; } /** * Provides a string representation of the elements in the given array. * * @param <T> The type of the array elements. * @param array An array of elements. * * @return string representation of elements in given array. */ public static <T> String toString(final T[] array) { return toString(array, "", ",", ""); } }