本文发表在 rolia.net 枫下论坛import java.util.*;
public class Collection1 {
public static Collection fill(Collection c, int start,int size) {
for(int i = start; i < start + size; i++)
c.add(Integer.toString(i));
return c;
}
public static Collection fill(Collection c,int size) {
return fill(c,0,size);
}
public static Collection fill(Collection c) {
return fill(c,0,10);
}
public static Collection newCollection() {
return fill(new ArrayList());
}
public static Collection newCollection(int start, int size) {
return fill(new ArrayList(),start,size);
}
public static void print(Collection c) {
for(Iterator x = c.iterator(); x.hasNext();)
System.out.println(x.next() + " ");
System.out.println();
}
public static void main(String[] args) {
Collection c = newCollection();
c.add("ten");
c.add("eleven");
print(c);
System.out.println("Collections.max(c) = " + Collections.max(c)); // which one is the max?
System.out.println("Collections.min(c) = " + Collections.min(c));
}
}
最大是eleven or ten?更多精彩文章及讨论,请光临枫下论坛 rolia.net
public class Collection1 {
public static Collection fill(Collection c, int start,int size) {
for(int i = start; i < start + size; i++)
c.add(Integer.toString(i));
return c;
}
public static Collection fill(Collection c,int size) {
return fill(c,0,size);
}
public static Collection fill(Collection c) {
return fill(c,0,10);
}
public static Collection newCollection() {
return fill(new ArrayList());
}
public static Collection newCollection(int start, int size) {
return fill(new ArrayList(),start,size);
}
public static void print(Collection c) {
for(Iterator x = c.iterator(); x.hasNext();)
System.out.println(x.next() + " ");
System.out.println();
}
public static void main(String[] args) {
Collection c = newCollection();
c.add("ten");
c.add("eleven");
print(c);
System.out.println("Collections.max(c) = " + Collections.max(c)); // which one is the max?
System.out.println("Collections.min(c) = " + Collections.min(c));
}
}
最大是eleven or ten?更多精彩文章及讨论,请光临枫下论坛 rolia.net