两种迭代器

public class Tests {


    @Test
    public void ceshi() {
        Map<Integer,String> map= StringUtilsByOs.BAD_TYPE_DICT;
        Set<Map.Entry<Integer,String>> set=map.entrySet();
        Iterator<Map.Entry<Integer,String>> iterator=set.iterator();
        while (iterator.hasNext()) {
            Map.Entry entry=iterator.next();
            System.out.println(entry.getKey()+","+entry.getValue());
        }

    }
    @Test
    public void ce(){
        Map<Integer,String> map= StringUtilsByOs.BAD_TYPE_DICT;
        Set<Integer>keySet=map.keySet();
        Iterator<Integer> keyIterator= keySet.iterator();
        while (keyIterator.hasNext()){
           Integer key= keyIterator.next();
            System.out.println(key);
            System.out.println(map.get(key));
        }

    }

 

展开阅读全文

没有更多推荐了,返回首页