Map/HashMap是java中一种很常用的数据结构,一般我们在应用中做的事情就是调用put向容器写入数据或者是get从容器读取数据。Map.entrySet()这个方法返回了键值对的集合,也是JDK官方推荐的遍历Map的方式。
Set<Map.Entry<String, String>> allEntrys = maps.entrySet();
for (Map.Entry<String, String> as : allEntrys)
{
String key = as.getKey();
String value = as.getValue();
}
public static void main(String[] args) throws Exception
{
HashMap<String, String> maps = new HashMap<String, String>();
maps.put("name", "xiu");
maps.put("age", "25");
System.out.println(maps);// {age=25, name=xiu}
Set<Map.Entry<String, Str

HashMap在Java中广泛使用,通常用于数据的存储和检索。然而,调用`Map.entrySet()`返回的键值对集合可能会引发安全性问题,因为它允许外部不可信代码访问并修改Map的内容。谨慎使用`entrySet()`以防止未授权操作。
最低0.47元/天 解锁文章
3052

被折叠的 条评论
为什么被折叠?



