本帖最后由 毅心缘 于 2014-7-4 00:49 编辑
楼主请看- import java.util.*;
- public class Test3 {
- public static void main(String[] args) {
- Map<String, String> map = new TreeMap<String, String>();
- map.put("23", "zhangsan");
- map.put("13","lisi" );
- map.put("54", "zhangjiafan");
- map.put("24", "fengxun");
- getKey(map);
- // getEntry();
- }
- public static void getKey(Map<String, String> map) {
- Set<String> keySet = map.keySet();
- Iterator<String> it = keySet.iterator();
- while (it.hasNext()) {
- String key = it.next();
- String value = map.get(key);
- System.out.println("key:" + key + " value:" + value);
- }
- }
- public static void getEntry(Map<String, String> map) {
- Set<Map.Entry<String, String>> entrySet = map.entrySet();
- Iterator<Map.Entry<String, String>> it = entrySet.iterator();
- while (it.hasNext()) {
- Map.Entry<String, String> ma = it.next();
- String key = ma.getKey();
- String value = ma.getValue();
- System.out.println("key:" + key + " value:" + value);
- }
- }
- }
复制代码
|