集合遍历

public class jihe {
    public static void main(String[] args) {
        HashSet hs = new HashSet();
        hs.add("1");
        hs.add("2");
        Iterator it = hs.iterator();
        while(it.hasNext()) {
            System.out.println(it.next());
        }
        Hashtable ht = new Hashtable<>();
        ht.put(1, "1");
        Iterator itt = ht.keySet().iterator();
        while(itt.hasNext()) {
            System.out.println(ht.get(itt.next()));
        }
        Iterator ittt = ht.entrySet().iterator();
        while(ittt.hasNext()) {
            Entry en = (Entry) ittt.next();
            System.out.println(en.getKey()+","+en.getValue());
        }
    }
}

posted @ 2018-09-09 22:05  萧愬夜  阅读(71)  评论(0)    收藏  举报