OnJava8-Examples/holding/PrintingContainers.java

41 lines
1.1 KiB
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: holding/PrintingContainers.java
// Containers print themselves automatically.
import java.util.*;
import static net.mindview.util.Print.*;
public class PrintingContainers {
static Collection fill(Collection<String> collection) {
collection.add("rat");
collection.add("cat");
collection.add("dog");
collection.add("dog");
return collection;
}
static Map fill(Map<String,String> map) {
map.put("rat", "Fuzzy");
map.put("cat", "Rags");
map.put("dog", "Bosco");
map.put("dog", "Spot");
return map;
}
public static void main(String[] args) {
2015-05-05 11:20:13 -07:00
print(fill(new ArrayList<>()));
print(fill(new LinkedList<>()));
print(fill(new HashSet<>()));
print(fill(new TreeSet<>()));
print(fill(new LinkedHashSet<>()));
print(fill(new HashMap<>()));
print(fill(new TreeMap<>()));
print(fill(new LinkedHashMap<>()));
2015-04-20 15:36:01 -07:00
}
} /* Output:
[rat, cat, dog, dog]
[rat, cat, dog, dog]
2015-05-05 11:20:13 -07:00
[cat, dog, rat]
2015-04-20 15:36:01 -07:00
[cat, dog, rat]
[rat, cat, dog]
2015-05-05 11:20:13 -07:00
{cat=Rags, dog=Spot, rat=Fuzzy}
2015-04-20 15:36:01 -07:00
{cat=Rags, dog=Spot, rat=Fuzzy}
{rat=Fuzzy, cat=Rags, dog=Spot}
*///:~