java集合map取key使用示例 java遍历map
程序员文章站
2024-02-21 10:12:04
复制代码 代码如下:for (iterator i = keys.iterator(); i.hasnext()  ...
复制代码 代码如下:
for (iterator i = keys.iterator(); i.hasnext()
{
string key = (string) i.next();
string value = (string) map.get(key);
text+=key + " = " + value;
}
复制代码 代码如下:
<span style="border-collapse: collapse; font-family: arial, 'liberation sans', 'dejavu sans', sans-serif; line-height: 18px; font-size: 14px; white-space: normal;"><pre class="lang-java prettyprint"><span>
</span></pre>
</span>
或者
or (map.entry<string,string> entry : map.entryset()) {
string key = entry.getkey();
string value = entry.getvalue();
// do stuff
} iterator<entry<string, string>> iterator = map.entryset().iterator();
复制代码 代码如下:
entry< string, string> entry;
while(iterator.hasnext()){
entry = iterator.next();
log.d("key value",entry.getkey()+" "+entry.getvalue());
}