Set collection
Duplicate elements are not allowed. Same method as Collection. There is only one way to retrieve the Set collection: iterator.
Common implementation classes:
HashSet:
HashSet
package demo;
import java.util.*;
public class Demo {
public static void main(String[] args) {
Set set=new HashSet();
set.add("haha");
set.add("aawdwad");
set.add("haha");//这里故意重复元素
set.add("啊啊啊111");
set.add("灌灌灌灌11222");
//取出元素--只能用迭代器
for(Iterator it=set.iterator();it.hasNext();) {
System.out.println(it.next());//打印结果不包含重复元素
}
}
}