请尊重原创,转载地址:http://blog.csdn.net/zhaokuo719/article/details/7445770
public
static
void
main(String[] args) {
Map<String, Object> map =
new
LinkedHashMap<String, Object>();
map.put(
"username"
,
"zhaokuo"
);
map.put(
"password"
,
"123456"
);
map.put(
"email"
,
"zhaokuo719@163.com"
);
map.put(
"sex"
,
"男"
);
for
(Map.Entry<String, Object> m :map.entrySet()) {
System.out.println(m.getKey()+
"\t"
+m.getValue());
}
Set set=map.entrySet();
Iterator iterator=set.iterator();
while
(iterator.hasNext()){
Map.Entry<String, Object> enter=(Entry<String, Object>) iterator.next();
System.out.println(enter.getKey()+
"\t"
+enter.getValue());
}
Iterator it = map.keySet().iterator();
while
(it.hasNext()){
String key;
String value;
key=it.next().toString();
value=(String) map.get(key);
System.out.println(key+
"--"
+value);
}
Iterator i=map.entrySet().iterator();
System.out.println( map.entrySet().size());
String key;
String value;
while
(i.hasNext()){
Map.Entry entry = (Map.Entry)i.next();
key=entry.getKey().toString();
value=entry.getValue().toString();
System.out.println(key+
"===="
+value);
}
System.out.println(getKeyByValue(map,
"zhaokuo"
));
}
[java]
view plain
copy
print
?
public
static
String getKeyByValue(Map map, Object value) {
String keys=
""
;
Iterator it = map.entrySet().iterator();
while
(it.hasNext()) {
Map.Entry entry = (Entry) it.next();
Object obj = entry.getValue();
if
(obj !=
null
&& obj.equals(value)) {
keys=(String) entry.getKey();
}
}
return
keys;
}
本文分享 CSDN - wangyonglin1123。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
来源:oschina
链接:https://my.oschina.net/u/4670056/blog/4745417