# 2020.02.27 集合练习题

`package com.guoyun.view;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Set;/** * ClassName: * Function:  ADD FUNCTION * Reason:   ADD REASON * * @author * @Date * @since Ver 1.1 */public class Test10 {    public static void main(String[] args) {        Map<Car2,Integer> map=new HashMap<>();        Car2 c1=new Car2("奥拓",100);        Car2 c2 = new Car2("宝马", 200);        Car2 c3 = new Car2("奔驰", 300);        map.put(c1,10000);        map.put(c2,500000);        map.put(c3,2000000);        Set<Car2> car2s = map.keySet();        for (Iterator<Car2> iterator = car2s.iterator(); iterator.hasNext(); ) {            Car2 next =  iterator.next();            System.out.println(next.getName());            if(next.getName().equals("宝马")){                System.out.println(map.get(next));            }        }        map.replace(c1,(int)(map.get(c1)*0.8));        map.replace(c2,(int)(map.get(c2)*0.8));        map.replace(c3,(int)(map.get(c3)*0.8));        for (Iterator<Car2> iterator = car2s.iterator(); iterator.hasNext(); ) {            Car2 next = iterator.next();            if (next.getName().equals("宝马")) {                System.out.println(map.get(next));            }        }    }}class Car2{    private String name;    private int speed;    public String getName() {        return name;    }    public int getSpeed() {        return speed;    }    @Override    public int hashCode() {        return name.hashCode();    }    @Override    public boolean equals(Object obj) {        if(this==obj){            return true;        }else if(obj instanceof Car2){            Car2 car2=(Car2) obj;            if(name.equals(car2.name)){                return true;            }        }        return false;    }    public Car2(String name, int speed) {        this.name = name;        this.speed = speed;    }}`

2020.02.27 集合练习题

(0)
(0)