e345. listing the elements of a collection.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 24 行
TXT
24 行
This example demonstrates how to iterate over the elements of various types of collections.
// For a set or list
for (Iterator it=collection.iterator(); it.hasNext(); ) {
Object element = it.next();
}
// For keys of a map
for (Iterator it=map.keySet().iterator(); it.hasNext(); ) {
Object key = it.next();
}
// For values of a map
for (Iterator it=map.values().iterator(); it.hasNext(); ) {
Object value = it.next();
}
// For both the keys and values of a map
for (Iterator it=map.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry)it.next();
Object key = entry.getKey();
Object value = entry.getValue();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?