- 论坛徽章:
- 0
|
在看java核心技术看到了如下这样的例子:
package cn.setframe;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class MapTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Map staff = new LinkedHashMap(101,0.75F,true);
staff.put("144-25-5464", new Employee("Angela Hung",12544));
staff.put("567-24-2546", new Employee("Harry Hacker",25415));
staff.put("157-62-7935", new Employee("Gary Cooper",654114));
staff.put("456-62-5527", new Employee("Francesca Cruz",24741));
//print all entries
System.out.println(staff);
//remove an entry
staff.remove("567-24-2546");
// replace an entry
staff.put("456-62-5527", new Employee("Francesca Miller",36241));
//look up a value
System.out.println(staff.get("157-62-7935"));
//iterate through all entries
Set entries = staff.entrySet();
Iterator iter = entries.iterator();
while(iter.hasNext()){
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object value = entry.getValue();
System.out.println("key="+key+", value="+value);
}
}
}
用红颜色标记的这个算法结构是什么意思?这个又是Map.Entry什么名堂? 大家来讨论讨论 |
|