ArrayUtils { public static String toString(Object[] a) { if (a == null) { return "null"; } if (a.length == 0) { return "[]"; } StringBuilder b = new StringBuilder("["); boolean first = true; for (Object o : a) { if (!first) { b.append(", "); } else { first = false; } b.append(o); } b.append(']'); return b.toString(); }  static int[] copyOf(int[] in, int length); @SuppressWarnings("unchecked") static T[] copyOf(T[] in, int length); @SuppressWarnings("unchecked") static T[] copyOfRange(T[] in, int start, int end); static String toString(Object[] a);  }
@Test public void testToString() { assertEquals("null", ArrayUtils.toString(null)); assertEquals("[]", ArrayUtils.toString(new Object[] {})); assertEquals("[1]", ArrayUtils.toString(new Object[] { 1 })); assertEquals("[1, 2]", ArrayUtils.toString(new Object[] { 1, 2 })); assertEquals("[null]", ArrayUtils.toString(new Object[] { null })); assertEquals("[a, 1, null]", ArrayUtils.toString(new Object[] { "a", 1, null })); }