本文直接上代碼,代碼分析
主要介紹常用的一個HashSet集合
//Set 集合的增删改查 無序 沒有重複對象
import java.util.*; //導包
public class Setzsgc {
public static void main(String[] args) {
HashSet hs = new HashSet();
//增加
HashSet s =new HashSet();
s.add("雨");
s.add("暴風");
hs.add("劍雨");
hs.add("冰");
hs.addAll(s);
hs.add("旱");
System.out.println(hs);
//删除
hs.remove("旱");
hs.removeAll(s);
System.out.println(hs);
//修改
hs.add("han");
System.out.println(hs);
TreeSet ts=new TreeSet();
ts.add("1春");
ts.add("2夏");
ts.add("3秋");
ts.add("4冬");
System.out.println(ts);
//顯示第一個
System.out.println(ts.first());
//顯示最後一個
System.out.println(ts.last());
System.out.println(ts.subSet("2夏","4冬"));
//删除
ts.remove("4冬");
System.out.println(ts);
}
}