- package 黑马练习;
- /*
- * MAP集合没有迭代器,可以转化为set集合 有两种取出方式
- */
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Set;
- import java.util.TreeMap;
- public class Map_tDemo {
- public static void main(String[] args) {
- Map<Integer,String> map = new TreeMap<Integer, String>();
- map.put(4, "lisi");
- map.put(5, "wangwu");
- map.put(6, "zhaoliu");
-
- Set<Integer> keyset = map.keySet();
- Iterator<Integer> it = keyset.iterator();
- while(it.hasNext()){
- int key = it.next();
- String value = map.get(key);
-
- System.out.println(key+":::"+value);
- }
-
- Set<Map.Entry<Integer, String>> entryset = map.entrySet();
- Iterator<Map.Entry<Integer, String>> it1 = entryset.iterator();
- while(it1.hasNext()){
- Map.Entry<Integer, String> me = it1.next();
- int key = me.getKey();
- String value = me.getValue();
- System.out.println(key+":::::"+value);
- }
- }
- }
复制代码
结果是一样一样的呀 |
|