Java使用entrySet方法检索Map集合中的元素
发布到2020-7-12|
复制链接
摘录:本文共享了用于使用entrySet方法检索Map集合中元素的特定代码。 具体内容如下
` ` ` java
/----------------
使用entrySet方法检索Map集合中的元素。
.此方法将Map集合中的key和value关系存储在Set集合中,该关系的数据类型为Map.En .
在本文中,我们将共享使用entrySet方法检索Map集合中元素的特定代码。 具体内容如下
` ` ` java
/----------------
使用entrySet方法检索Map集合中的元素。
.此方法将Map集合中的key-value关系存储在Set集合中,该关系的数据类型为Map.Entry
. entrySet方法的返回类型的具体写法是Set
----------------- * /
package pack04;
import java.util.*;
公共类映射
publicstaticvoidmain (字符串[ ] args ) {
Map ma=new HashMap (;
//在集合中加入元素
ma.put(1,' abc01 '; //这里自动装箱基本数据类型
ma.put(2,' abc02 ';
ma.put(3,' abc03 ';
ma.put(4,' abc04 ';
从//map集合中提取映射关系并将其存储在Set集合中
Set entryset=ma.entrySet (;
//取迭代器
Iterator it=entryset.iterator (;
获取//map集合的元素
while(it.Hasnext ) ) ) )。
Map.Entry en=it.next (;
Integer maKey=en.getKey (;
String maValue=en.getValue (;
system.out.println (makey ' : ' ma value );
}
}
}
``````