美文网首页
set与iterator

set与iterator

作者: bluewind1230 | 来源:发表于2018-01-11 09:21 被阅读0次
    import javax.xml.soap.Text;
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.Set;
    
    public class Main {
        public static  class Test {
            @Override
            public boolean equals(Object obj) {
                return true;
            }
    
            @Override
            public int hashCode() {
                return 0x100;
            }
        }
    
        public static void main(String[] args) {
        Set<String> sets = new HashSet<>();
            sets.add("hello");
            sets.add("hello");//内容重复只显示一个
            sets.add("world");
    
    
            Iterator<String> iterator = sets.iterator();
            while (iterator.hasNext()){
                System.out.println(iterator.next());
    
            }
    
    
            //测试
            System.out.println("--------------");
            Set<Test> set = new HashSet<>();
    
    
            Test test = new Test();
            set.add(test);
            set.add(test);
            set.add((new Test()));
            set.add((new Test()));
            set.add((new Test()));
    
            Iterator<Test> iteratorA = set.iterator();
          while (iteratorA.hasNext()){
                System.out.println(iteratorA.next());
    
            }
    
        }
    
    }
    
    

    相关文章

      网友评论

          本文标题:set与iterator

          本文链接:https://www.haomeiwen.com/subject/nfhznxtx.html