建立一個HasMap物件,並在其中新增一些員工的姓名和工資:張三,8000,李四,6000.然後從HashMap物件中獲取這兩個人的薪水並打印出來,接著把張三的工資改為85000,再把他們的薪水顯示出
阿新 • • 發佈:2019-01-28
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()); } } }