public class Test02 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Map<String, Dog> map = new HashMap<String, Dog>();
map.put("大大", new Dog("一號",5,"軍犬"));
map.put("小小", new Dog("二號",8,"盲犬"));
map.put("牛牛", new Dog("三號",1,"獵犬"));
// System.out.println("是否含鍵:" + map.containsKey("大大"));
if(map.containsKey("大大")) {
System.out.println(map.get("大大"));
}else {
System.out.println("查找錯誤");
}
}
}
根據寵物暱稱查找對應寵物,如果找到,顯示寵物信息,否則給出錯誤提示
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.