public static void main(String[] args) {
   List<Pet> petList = Pets.arrayList(8);
   Set<Pet> petSet = new HashSet<Pet>(petList);
   Map<String, Pet> petMap = new LinkedHashMap<String, Pet>();
   String[] names = ("Ralph, Eric, Robin, Lacey, " + "Britney, Sam, Spot, Fluffy").split(", ");
   for (int i = 0; i < names.length; i++) petMap.put(names[i], petList.get(i));
   display(petList);
   display(petSet);
   display(petList.iterator());
   display(petSet.iterator());
   System.out.println(petMap);
   System.out.println(petMap.keySet());
   display(petMap.values());
   display(petMap.values().iterator());
 }
Exemplo n.º 2
0
 public static void main(String[] args) {
   Map<String, Pet> petMap = new HashMap<String, Pet>();
   petMap.put("My Cat", new Cat("Molly"));
   petMap.put("My Dog", new Dog("Ginger"));
   petMap.put("My Hamster", new Hamster("Bosco"));
   print(petMap);
   Pet dog = petMap.get("My Dog");
   print(dog);
   print(petMap.containsKey("My Dog"));
   print(petMap.containsValue(dog));
 }