e353. operating on sets.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 25 行

TXT
25 行
字号
See also e352 Creating a Set. 
    // Create the sets
    Set set1 = new HashSet();
    Set set2 = new HashSet();
    
    // Add elements to the sets ...
    
    // Copy all the elements from set2 to set1 (set1 += set2)
    // set1 becomes the union of set1 and set2
    set1.addAll(set2);
    
    // Remove all the elements in set1 from set2 (set1 -= set2)
    // set1 becomes the asymmetric difference of set1 and set2
    set1.removeAll(set2);
    
    // Get the intersection of set1 and set2
    // set1 becomes the intersection of set1 and set2
    set1.retainAll(set2);
    
    // Remove all elements from a set
    set1.clear();

 Related Examples 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?