map作业三
package cn.usts.edu.homework;
import java.util.*;
/**
* @author :fly
* @description:
* @date :2021/11/4 13:06
*/
public class EmployeeDemo {
public static void main(String[] args) {
Map m = new HashMap();
m.put("jack",650);
m.put("tom",1200);
m.put("smith",2900);
System.out.println("=========for遍历=========");
Set keySet = m.keySet();
for (Object key : keySet) {
int sal =(int) m.get(key);
System.out.println(key+"---"+sal+"元");
}
// entrySet遍历
System.out.println("=========entrySet迭代器遍历=========");
Set entrySet = m.entrySet();
Iterator iterator = entrySet.iterator();
while (iterator.hasNext()){
Map.Entry next = (Map.Entry) iterator.next();
System.out.println(next.getKey()+"---"+next.getValue()+"元");
}
System.out.println("=========修改jack=========");
m.replace("jack",2600);
m.forEach((key,value)-> System.out.println(key+"---"+value+"元"));
// m.put("jack",26000);
System.out.println("=========+100=========");
m.forEach((key,value)->{m.replace(key,(int)value+100);});
m.forEach((key,value)-> System.out.println(key+"---"+value+"元"));
System.out.println("=========遍历工资=========");
Collection values = m.values();
for (Object value : values) {
System.out.println("工资:"+value);
}
}
}