entry 遍历 Map 元素
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+"\t"); System.out.println("dateMap的value:"+value); } } }
2、结果
"C:\Program Files\Java\jdk1.8.0_181\bin\java.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
缘于生活,而归于工作。本人所书,而意于分享。
如有转载,请注明出处!
--活出自己范儿