在Java中,可以使用entrySet()方法来遍历LinkedHashMap
在Java中,可以使用entrySet()
方法来遍历LinkedHashMap。具体步骤如下:
- 获取LinkedHashMap的entrySet
- 遍历entrySet中的元素
示例代码如下:
LinkedHashMap<String,Integer>linkedHashMap=newLinkedHashMap<>();
linkedHashMap.put("A",1);
linkedHashMap.put("B",2);
linkedHashMap.put("C",3);
for(Map.Entry<String,Integer>entry:linkedHashMap.entrySet()){
System.out.println("Key:"+entry.getKey()+",Value:"+entry.getValue());
}
上面的代码会输出:
Key:A,Value:1
Key:B,Value:2
Key:C,Value:3
版权声明
本文仅代表作者观点,不代表博信信息网立场。