set 得遍历

package find;


import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;


/**
 * @author foxz
 */
public class setFind {

    public static void main(String[] args) {
        Set<String> set = new HashSet<String>();

        set.add("1");
        set.add("2");
        set.add("3");
        set.add("4");

        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            System.out.println(str);
        }

        System.out.println("================================================");

        for (String str : set) {
            System.out.println(str);
        }

        System.out.println("================================================");

        Set<Object> setTwo = new HashSet<Object>();

        setTwo.add("1");
        setTwo.add("2");
        setTwo.add("3");
        setTwo.add("4");

        for (Object obj: setTwo) {
            System.out.println(obj);
        }
    }
}

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页