implement Arrays.toString()

This commit is contained in:
Joel Dice 2007-08-23 19:57:42 -06:00
parent 009a743aa8
commit d1dbb45d55
2 changed files with 21 additions and 0 deletions

View File

@ -3,12 +3,20 @@ package java.util;
public class Arrays {
private Arrays() { }
public static String toString(Object[] a) {
return asList(a).toString();
}
private static boolean equal(Object a, Object b) {
return (a == null && b == null) || (a != null && a.equals(b));
}
public static <T> List<T> asList(final T ... array) {
return new List<T>() {
public String toString() {
return Collections.toString(this);
}
public int size() {
return array.length;
}

View File

@ -3,6 +3,19 @@ package java.util;
public class Collections {
private Collections() { }
static String toString(List l) {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (Iterator it = l.iterator(); it.hasNext();) {
sb.append(it.next());
if (it.hasNext()) {
sb.append(",");
}
}
sb.append("]");
return sb.toString();
}
static class IteratorEnumeration<T> implements Enumeration<T> {
private final Iterator<T> it;