集合遍历

it2022-05-27  78

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());        }    }}

转载于:https://www.cnblogs.com/xiaosuye/p/9615428.html

相关资源:map集合遍历的五种方法

最新回复(0)