Set接口
Set接口
Set是一个无序,无下标,不可重复的集合
Set接口方法完全继承自Collection
实践:
package com.qianfeng.collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
* 功能描述
*
* @since 2022-05-12
*/
public class SetDemo {
public static void main(String[] args) {
Set<String> set = new HashSet<>();
set.add("hahaha");
set.add("heiheihei");
set.add("hehehe");
set.add("hehehe");
set.remove("hehehe");
Iterator<String> iterator = set.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
System.out.println(set.isEmpty());
System.out.println(set.contains("haha"));
}
}