package com.lanxi.demo1_3;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class TestHash {
public static void main(String[] args) {
Set hash=new HashSet();
hash.add("明");
hash.add("天");
hash.add("最");
hash.add("好");
hash.add("的");
hash.add("准");
hash.add("备");
hash.add("是");
System.out.print("集合中的字符串信息为:");
Iterator it=hash.iterator();
while(it.hasNext()){
System.out.print(it.next());
}
System.out.println();
StringBuffer buf=new StringBuffer();
buf.append(hash);
System.out.println("buf里的内容为:"+buf);
System.out.println("buf长度为:"+buf.length());
System.out.println("从集合中删除“是”:"+hash.remove("是"));
System.out.println("集合长度:"+hash.size());
System.out.println("集合中是否包含“是”:"+hash.contains("是"));
System.out.println("集合是否为空:"+hash.isEmpty()); } }
运行结果