1、书写类
import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; public class test { public static void main(String args[]){ Map<String,String> dateMap = new HashMap<String,String>(); dateMap.put("small","sun"); dateMap.put("king","wang"); dateMap.put("sun","shine"); for(Entry<String,String> dateEntry:dateMap.entrySet()){ String key = dateEntry.getKey(); String value=dateEntry.getValue(); System.out.print("dateMap的key:"+key+" "); System.out.println("dateMap的value:"+value); } } }
2、结果
"C:Program FilesJavajdk1.8.0_181injava.exe"... dateMap的key:small dateMap的value:sun dateMap的key:sun dateMap的value:shine dateMap的key:king dateMap的value:wang Process finished with exit code 0