// 第一种方法(传统方法)
public void runOne()
{
Map map = new HashMap();
map.put("01", "java01");
map.put("02", "java02");
map.put("03", "java03");
Set set = map.keySet();
Iterator it = set.iterator();
while (it.hasNext())
{
String key = (String) it.next();
String value = (String) map.get(key);
System.out.println(key + "=" + value);
}
}
// 第二种方法(传统方法)
public void runTwo() {
Map map = new HashMap();
map.put("01", "java01");
map.put("02", "java02");
map.put("03", "java03");
Set set = map.entrySet();
Iterator it = set.iterator();
while (it.hasNext()) {
Entry entry = (Entry) it.next();
String key = (String) entry.getKey();
String value = (String) entry.getValue();
System.out.println(key + "=" + value);
}
}
// 第三种方法(增强for循环方法)
public void runThree() {
Map map = new LinkedHashMap();
map.put("01", "java01");
map.put("02", "java02");
map.put("03", "java03");
for (Object obj : map.keySet()) {
String key = (String) obj;
String value = (String) map.get(key);
System.out.println(key + "=" + value);
}
}
// 第四种方法(增强for循环方法)
public void runFour() {
Map map = new LinkedHashMap();
map.put("01", "java01");
map.put("02", "java02");
map.put("03", "java03");
for (Object obj : map.entrySet()) {
Entry entry = (Entry) obj;
String key = (String) entry.getKey();
String value = (String) entry.getValue();
System.out.println(key + "=" + value);
|