HashSet集合

2019-03-19  本文已影响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);

}

}

}

上一篇 下一篇

猜你喜欢

热点阅读