-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPetMap.java
More file actions
28 lines (25 loc) · 647 Bytes
/
PetMap.java
File metadata and controls
28 lines (25 loc) · 647 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package chapter11;
import static net.mindview.util.Print.*;
import java.util.HashMap;
import java.util.Map;
class Pet{
private String name;
Pet(String name){
this.name = name;
}
public String toString(){
return this.name;
}
}
public class PetMap {
public static void main(String[] args) {
Map<String, Pet> petMap = new HashMap<String, Pet>();
petMap.put("My Cat", new Pet("Molly"));
petMap.put("My Dog", new Pet("Ginger"));
petMap.put("My Hamster",new Pet("Bosco"));
print(petMap);
Pet dog = petMap.get("My Dog");
print(petMap.containsKey("My Dog"));
print(petMap.containsValue(dog));
}
}