Map / HashMap 获取Key值的方法

方法1:keySet()

HashMap hashmp = ne HashMap();
hashmp.put("aa", "111");
Set set = hashmp.keySet();
Iterator iter = set.iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
// printkey
}
// traverse
for (String key : list.get(pos).keySet() ) {
myKey = key;
}


方法2:entrySet()
HashMap map;
Iterator i = map.entrySet().iterator();
while (i.hasNext()) {
Object obj = i.next();
String key = obj.toString();
}
// or
while (i.hasNext()) {
Entry entry = (java.util.Map.Entry)it.next();
entry.getkey();
entry.getValue();
}


方法1:keySet()
HashMap hashmp = ne HashMap();
hashmp.put("aa", "111");
Set set = hashmp.keySet();
Iterator iter = set.iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
// printkey
}
// traverse
for (String key : list.get(pos).keySet() ) {
myKey = key;
}


方法2:entrySet()
HashMap map;
Iterator i = map.entrySet().iterator();
while (i.hasNext()) {
Object obj = i.next();
String key = obj.toString();
}
// or
while (i.hasNext()) {
Entry entry = (java.util.Map.Entry)it.next();
entry.getkey();
entry.getValue();
}

阅读更多
个人分类: java
上一篇Javascript跨域访问解决方案
下一篇SA,SD和SE的差别
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭