创建一个HasMap对象,并在其中添加一些员工的姓名和工资:张三,8000,李四,6000.然后从HashMap对象中获取这两个人的薪水并打印出来,接着把张三的工资改为85000,再把他们的薪水显示出

package com.dh.ch07;


import java.util.*;


public class HashMapTest {


	public static void main(String[] args) {
		HashMap<String,Integer>hashMap = new HashMap<String,Integer>();
		hashMap.put("zhangsan",8008);
		hashMap.put("lisi",6000);
		Set<Map.Entry<String, Integer>> set = hashMap.entrySet();
		for(Map.Entry<String,Integer>entry:set) {
			System.out.println(entry.getKey()+":"+entry.getValue());
		}
		System.out.println("Modify....................");
		hashMap.put("zhangsan", 8500);
		
		for(Map.Entry<String,Integer>entry1:set) {
			System.out.println(entry1.getKey()+":"+entry1.getValue());
		
		}
	}


}

猜你喜欢

转载自blog.csdn.net/qq_38900441/article/details/80728196