Map的几种取值方法

public static void main(String[] args) throws IOException,ParseException {

Map<String,String> m = new HashMap<String,String>();

m.put("1", "haha");

m.put("2", "hehe");

m.put("3", "heihei");

 //第一种

for(String k : m.keySet())

{

System.out.println(k+m.get(k));

}

 //第二种

for(Map.Entry<String, String> d:m.entrySet())

{

System.out.println(d.getValue()+d.getKey());

}

 //第三种

Set<String> x = m.keySet();

Iterator it = x.iterator();

while(it.hasNext())

{

String u = (String) it.next();

System.out.println(u+m.get(u));

}

 //第四种

Set<Map.Entry<String, String>> y = m.entrySet();

Iterator<Map.Entry<String, String>> it1 = m.entrySet().iterator();

while(it1.hasNext())

{

Map.Entry<String, String> en = it1.next();

System.out.println(en.getKey()+en.getValue());

}

}

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

Hive 删除行, 表 ,清空表

删除行A表数据如下id(String)       name(String)\1                       aaa2                      bbb3                      ccc\

HashMap 初始化时赋值

一般初始化一个map并且给map赋值的写法:HashMap<String,StringmapnewHashMap<String,String();map.put("name","test");map.put("age","20");但是我想在初始化的时候就直接给map中set值。

HIVE 时间操作函数

日期函数UNIX时间戳转日期函数: from\_unixtime语法:   from\_unixtime(bigint unixtime\, string format\)返回值: string说明: 转化UNIX时间戳(从19700101 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式举例:hive   selec