@Test public void testToString_NullSeparator() { final List<String> twoElementList = Arrays.asList("1", "2"); Assert.assertEquals(twoElementList.toString(), CollectionUtil.toString(twoElementList, null)); }
public static String toString(final Collection<?> collection, final String separator) { if (collection == null || collection.isEmpty()) { return ""; } if (separator == null) { return collection.toString(); } final StringBuilder builder = new StringBuilder(collection.size() * (16 + separator.length())); boolean addSeparator = false; for (final Object collectionElement : collection) { if (addSeparator) { builder.append(separator); } else { addSeparator = true; } if (collectionElement != null) { builder.append(collectionElement.toString()); } } return builder.toString(); }
CollectionUtil { public static String toString(final Collection<?> collection, final String separator) { if (collection == null || collection.isEmpty()) { return ""; } if (separator == null) { return collection.toString(); } final StringBuilder builder = new StringBuilder(collection.size() * (16 + separator.length())); boolean addSeparator = false; for (final Object collectionElement : collection) { if (addSeparator) { builder.append(separator); } else { addSeparator = true; } if (collectionElement != null) { builder.append(collectionElement.toString()); } } return builder.toString(); } }
CollectionUtil { public static String toString(final Collection<?> collection, final String separator) { if (collection == null || collection.isEmpty()) { return ""; } if (separator == null) { return collection.toString(); } final StringBuilder builder = new StringBuilder(collection.size() * (16 + separator.length())); boolean addSeparator = false; for (final Object collectionElement : collection) { if (addSeparator) { builder.append(separator); } else { addSeparator = true; } if (collectionElement != null) { builder.append(collectionElement.toString()); } } return builder.toString(); }  }
CollectionUtil { public static String toString(final Collection<?> collection, final String separator) { if (collection == null || collection.isEmpty()) { return ""; } if (separator == null) { return collection.toString(); } final StringBuilder builder = new StringBuilder(collection.size() * (16 + separator.length())); boolean addSeparator = false; for (final Object collectionElement : collection) { if (addSeparator) { builder.append(separator); } else { addSeparator = true; } if (collectionElement != null) { builder.append(collectionElement.toString()); } } return builder.toString(); }  static boolean containsInstance(final Collection<? extends T> collection, final T instance); static int indexOfInstance(final Collection<? extends T> collection, final T instance); static Map<T, AtomicInteger> countOccurrences(final Collection<T> collection); static void moveEntryInInsertSortedMap(final Map<K, V> insertSortedMap, final K entryKey, final boolean increaseIndexByOne); static String toString(final Collection<?> collection, final String separator); }
CollectionUtil { public static String toString(final Collection<?> collection, final String separator) { if (collection == null || collection.isEmpty()) { return ""; } if (separator == null) { return collection.toString(); } final StringBuilder builder = new StringBuilder(collection.size() * (16 + separator.length())); boolean addSeparator = false; for (final Object collectionElement : collection) { if (addSeparator) { builder.append(separator); } else { addSeparator = true; } if (collectionElement != null) { builder.append(collectionElement.toString()); } } return builder.toString(); }  static boolean containsInstance(final Collection<? extends T> collection, final T instance); static int indexOfInstance(final Collection<? extends T> collection, final T instance); static Map<T, AtomicInteger> countOccurrences(final Collection<T> collection); static void moveEntryInInsertSortedMap(final Map<K, V> insertSortedMap, final K entryKey, final boolean increaseIndexByOne); static String toString(final Collection<?> collection, final String separator);  }