java濡備綍閬嶅巻map鐨刱ey
Java涓彲浠ヤ娇鐢ㄨ凯浠e櫒锛圛terator锛夋垨鑰呭寮哄瀷for寰幆锛坒orEach锛夋潵閬嶅巻Map鐨刱ey銆?/p>
浣跨敤杩唬鍣ㄩ亶鍘哅ap鐨刱ey鐨勭ず渚嬩唬鐮佸涓嬶細
Map<String, Integer> map = new HashMap<>();
// 娣诲姞鍏冪礌鍒癕ap
Iterator<String> iterator = map.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
System.out.println(key);
}
浣跨敤澧炲己鍨媐or寰幆閬嶅巻Map鐨刱ey鐨勭ず渚嬩唬鐮佸涓嬶細
Map<String, Integer> map = new HashMap<>();
// 娣诲姞鍏冪礌鍒癕ap
for (String key : map.keySet()) {
System.out.println(key);
}
浠ヤ笂鏄袱绉嶅父鐢ㄧ殑閬嶅巻Map鐨刱ey鐨勬柟娉曪紝鍙互鏍规嵁鍏蜂綋闇€姹傞€夋嫨閫傚悎鐨勬柟寮忋€?/p>
相关问答