@Test public void testToString() { Assert.assertEquals("null", CollectionUtils.toString(null)); List<String> stringList = new ArrayList<String>(); Assert.assertEquals("{}", CollectionUtils.toString(stringList)); stringList.add("foo"); Assert.assertEquals("{foo}", CollectionUtils.toString(stringList)); stringList.add("bar"); Assert.assertEquals("{foo,bar}", CollectionUtils.toString(stringList)); stringList.add(null); Assert.assertEquals("{foo,bar,null}", CollectionUtils.toString(stringList)); List<Foo> fooList = new ArrayList<Foo>(); Assert.assertEquals("{}", CollectionUtils.toString(fooList)); fooList.add(new Foo("1")); Assert.assertEquals("{foo1}", CollectionUtils.toString(fooList)); fooList.add(new Foo("2")); Assert.assertEquals("{foo1,foo2}", CollectionUtils.toString(fooList)); fooList.add(null); Assert.assertEquals("{foo1,foo2,null}", CollectionUtils.toString(fooList)); }
public static String toString(final Collection<?> collection) { if (collection == null) return String.valueOf(collection); final StringBuilder result = new StringBuilder().append("{"); String elementSeparator = ""; for (final Object element : collection) { result.append(elementSeparator); result.append(String.valueOf(element)); elementSeparator = ","; } result.append("}"); return result.toString(); }
CollectionUtils { public static String toString(final Collection<?> collection) { if (collection == null) return String.valueOf(collection); final StringBuilder result = new StringBuilder().append("{"); String elementSeparator = ""; for (final Object element : collection) { result.append(elementSeparator); result.append(String.valueOf(element)); elementSeparator = ","; } result.append("}"); return result.toString(); } }
CollectionUtils { public static String toString(final Collection<?> collection) { if (collection == null) return String.valueOf(collection); final StringBuilder result = new StringBuilder().append("{"); String elementSeparator = ""; for (final Object element : collection) { result.append(elementSeparator); result.append(String.valueOf(element)); elementSeparator = ","; } result.append("}"); return result.toString(); } private  CollectionUtils(); }
CollectionUtils { public static String toString(final Collection<?> collection) { if (collection == null) return String.valueOf(collection); final StringBuilder result = new StringBuilder().append("{"); String elementSeparator = ""; for (final Object element : collection) { result.append(elementSeparator); result.append(String.valueOf(element)); elementSeparator = ","; } result.append("}"); return result.toString(); } private  CollectionUtils(); static String toString(final Collection<?> collection); static int getLastIndex(final Collection<?> collection); static boolean isEmpty(final Collection<?> collection); }
CollectionUtils { public static String toString(final Collection<?> collection) { if (collection == null) return String.valueOf(collection); final StringBuilder result = new StringBuilder().append("{"); String elementSeparator = ""; for (final Object element : collection) { result.append(elementSeparator); result.append(String.valueOf(element)); elementSeparator = ","; } result.append("}"); return result.toString(); } private  CollectionUtils(); static String toString(final Collection<?> collection); static int getLastIndex(final Collection<?> collection); static boolean isEmpty(final Collection<?> collection);  }