美文网首页
HashSet集合

HashSet集合

作者: 最美是夫诸 | 来源:发表于2019-03-19 09:13 被阅读0次

Set接口的特点   

Set体系的集合:

    A:存入集合的顺序和取出集合的顺序不一致

    B:没有索引

    C:存入集合的元素没有重复

HashSet使用&唯一性原理

HashSet的使用

案例代码一:

    public class HashSetDemo2 {

public static void main(String[] args) {

//创建集合对象

HashSetnew HashSet<Student>();

//创建元素对象

Student s = new Student("zhangsan",18);

Student s2 = new Student("lisi",19);

Student s3 = new Student("lisi",19);

//添加元素对象

hs.add(s);

hs.add(s2);

hs.add(s3);

//遍历集合对象

for (Student student : hs) {

System.out.println(student);

}

}

}

相关文章

网友评论

      本文标题:HashSet集合

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