首页 > 编程知识 正文

map获取所有的value(java的entryset_Java使用entrySet方法获取Map集合中的元素)

时间:2023-05-06 11:25:02 阅读:123492 作者:1094

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 );

}

}

}

``````

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。