集册 Java实例教程 获取HashSet的大小

获取HashSet的大小

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

926
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取哈希集的大小

 /* from 时代Java - N o w  J a v a . c o m*/

import java.util.HashSet;

 

public class Main {

 

  public static void main(String[] args) {

    HashSet hSet = new HashSet();

    System.out.println("Size of HashSet : " + hSet.size());

   

    //add elements to HashSet object

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

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

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

 

    System.out.println("Size of HashSet after addition : " + hSet.size());

   

    //remove one element from HashSet using remove method

    hSet.remove(new 
展开阅读全文