Map 取值简介方便

 Map map=new HashMap();

map.put(1,"ceshi");

map.put(2,"ceshiu01");

Iterator it=map.keyset().iterator();

 int i=0;

while(it.Hashnext){

  i=it.next();

  logger.info("通过键取对应的值"+map.get(i));

}

之前对Map 取值都通过先取出来的keySet(),先取出来键。然后通过键取对应的值在while中。实在是太麻烦了。

通过一个简洁的取值方式 Entry 接口。直接取就行了 想取多少,取多少。 废话不多说,直接上代码

 Map map=new HashMap();

map.put(1,"ceshi");

map.put(2,"ceshiu01");

Iterator it=map.entryset().iterator();

 int i=0;

while(it.Hashnext){

   Map.Entry<int,String) me=(Map.Entry<int,String))it.next();

  logger.info("键"+me.getkey());

logger.info("键对应的值"+m.getvalue());

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值