首先看一個例子:
Set operations: union(並集), intersection(交集),asymetric difference(非對稱差集), symmetric difference(對稱差集), is subset(子集), is superset(超集)
這裏很重要的是,一些集合操作會修改原始集合,比如addAll,retainAll,removeAll。尤其是你要重複操作原始集合的時候,一定要新建一個集合,new
TreeSet<T>
(
orginalSet
)。
參考:
http://www.java2s.com/Code/Java/Collections-Data-Structure/Set.htm