package test12;

 import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set; public class Entre_Demo {
public static void main(String ... args){
mapEntre(); }
public static void mapEntre(){
Map<String,Integer> map=new HashMap<>();
map.put("tom",);
map.put("ok",);
Set<Map.Entry<String,Integer>> mapen=map.entrySet();//泛型内嵌套泛型。获得是Set集合。
Iterator<Map.Entry<String,Integer>> mapit=mapen.iterator();
while (mapit.hasNext()){
Map.Entry<String,Integer> mape=mapit.next();
// String mapkey=mapit.next().getKey();
String mapkey=mape.getKey();//获取键值
Integer mapval=mape.getValue();//获得val。
// Integer mapval=mapit.next().getValue();
System.out.print(mapkey+"-------------------"+mapval);
}
}
}

Map的方法中entrySet()返回是Set集合,集合内的对象类型为:Map.Entry<k,v>类型,属于泛型中嵌套另一个类型。

Set<Map.Entry<K,V>>      entrySet()

Interface Map.Entry<K,V> 提供的方法。entrySet()是返回的是这个接口实现类的对象。

看下方法:

K   getKey()

V     getValue()

V     setValue(V value) 设置新的value值。

mapent的更多相关文章

  1. java 集合(五)MapDemo

    package cn.sasa.demo3; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedH ...

随机推荐

  1. Linux 文件缓存 (二)

    close系统调用入口1. 首先来到系统调用入口,主要使用__close_fd进行了具体的处理过程,并没有耗时操作.(current->files表示进程当前打开文件表信息,fd为需要关闭的文件 ...

  2. 一文理解JS的节流、防抖及使用场景

    函数防抖(debounce):在事件被触发n秒后再执行回调,如果在这n秒内又被触发,则重新计时. 看一个

  3. iframe跨源报错:"Blocked a frame with origin from accessing a cross-origin frame"

    一.报错信息: “Blocked a frame with origin from accessing a cross-origin frame” 二.在stackoverflow上找到原因 Same ...

  4. 【vue】webpack插件svg-sprite-loader---实现自己的icon组件

    引言:最近开始写vue的项目,借鉴了一下vue-element-admin源码,针对vue有一个关于icon图标的处理,最近也找了很多关于vue的icon处理的解决方案,大部分都是按照之前小程序的方式 ...

  5. Android EditText方框验证码 短信验证码攻略

    本文由xiawe_i提供. xiawe_i的博客地址是: http://www.jianshu.com/u/fa9f03a240c6 项目中有这样一个需求: 验证码页是四个方框,输入验证码方框颜色改变 ...

  6. Ubuntu-18.04 下修改root用户密码,安装SSH服务,允许root用户远程登录,安装vsftp服务器

    修改root用户密码 打开终端,输入 sudo passwd root 指令: 安装SSH服务 ssh默认端口号是22,可以在/etc/ssh/sshd_config文件中修改 查看服务器否开启:ne ...

  7. poj_3628 Bookshelf 2

    Description Farmer John recently bought another bookshelf for the cow library, but the shelf is gett ...

  8. SqlServer查询存储过程中包含指定的内容

    存储过程太多,有时只记得存储过程里面的某一点类容,想要找到对应的存储过程: SELECT obj.Name 存储过程名, sc.TEXT 存储过程内容 FROM syscomments sc INNE ...

  9. makedown 软件

    windows上的新手使用makedownpad 很适合的 下载之后你需要激活makedownpad MarkdownPad 2 Pro 注册码(邮箱+许可密钥) 邮箱 Soar360@live.co ...

  10. [翻译] AYVibrantButton

    AYVibrantButton https://github.com/a1anyip/AYVibrantButton AYVibrantButton is a stylish button with ...