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("查找错误"); } } }
根据宠物昵称查找对应宠物,如果找到,显示宠物信息,否则给出错误提示
猜你喜欢
转载自blog.csdn.net/weixin_39788493/article/details/80777439
今日推荐
周排行