集册 Java实例教程 从HashSet中删除所有元素

从HashSet中删除所有元素

欢马劈雪     最近更新时间:2020-01-02 10:19:05

687
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从哈希集中删除所有元素


import java.util.HashSet;
/**
nowjava.com 提供 
**/

 

public class Main {

 

  public static void main(String[] args) {

    HashSet hSet = new HashSet();

   

    hSet.add(new Integer("1"));

    hSet.add(new Integer("2"));

    hSet.add(new Integer("3"));

   

    System.out.println("HashSet before removal : " + hSet);

    hSet.clear();

    System.out.println("HashSet after removal : " + hSet);

    System.out.println("Is HashSet empty ? " + hSet.isEmpty());    

  }

}