MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / PrintingCollections

Class PrintingCollections

collections/PrintingCollections.java:8–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6import java.util.*;
7
8public class PrintingCollections {
9 static Collection
10 fill(Collection<String> collection) {
11 collection.add("rat");
12 collection.add("cat");
13 collection.add("dog");
14 collection.add("dog");
15 return collection;
16 }
17 static Map fill(Map<String, String> map) {
18 map.put("rat", "Fuzzy");
19 map.put("cat", "Rags");
20 map.put("dog", "Bosco");
21 map.put("dog", "Spot");
22 return map;
23 }
24 public static void main(String[] args) {
25 System.out.println(fill(new ArrayList<>()));
26 System.out.println(fill(new LinkedList<>()));
27 System.out.println(fill(new HashSet<>()));
28 System.out.println(fill(new TreeSet<>()));
29 System.out.println(fill(new LinkedHashSet<>()));
30 System.out.println(fill(new HashMap<>()));
31 System.out.println(fill(new TreeMap<>()));
32 System.out.println(fill(new LinkedHashMap<>()));
33 }
34}
35/* Output:
36[rat, cat, dog, dog]
37[rat, cat, dog, dog]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected