📜  设置删除元素 java 代码示例

📅  最后修改于: 2022-03-11 14:52:26.563000             🧑  作者: Mango

代码示例1
// Java code to illustrate Set.remove() method
  
import java.util.*;
  
public class SetDemo {
    public static void main(String args[])
    {
        // Creating an empty Set
        Set set = new HashSet();
  
        // Use add() method to add elements into the Set
        set.add("Welcome");
        set.add("To");
        set.add("Geeks");
        set.add("4");
        set.add("Geeks");
  
        // Displaying the Set
        System.out.println("Set: " + set);
  
        // Removing elements using remove() method
        set.remove("Geeks");
        set.remove("4");
        set.remove("Welcome");
  
        // Displaying the Set after removal
        System.out.println("Set after removing elements: "
                           + set);
    }
}