目录

int size()

描述 (Description)

size()方法用于获取此集合中的元素数量(基数)。

声明 (Declaration)

以下是java.util.TreeSet.size()方法的声明。

public int size()

参数 (Parameters)

NA

返回值 (Return Value)

方法调用返回此集合中的元素数。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.util.TreeSet.size()方法的用法。

package com.iowiki;
import java.util.TreeSet;
public class TreeSetDemo {
   public static void main(String[] args) {
      // creating a TreeSet 
      TreeSet <Integer>treeadd = new TreeSet<Integer>();
      // adding in the tree set
      treeadd.add(1);
      treeadd.add(13);
      treeadd.add(17);
      treeadd.add(2);
      // Size of the tree set
      System.out.println("Size of the tree set is: "+treeadd.size());      
   }     
}

让我们编译并运行上面的程序,这将产生以下结果。

Size of the tree set is: 4
↑回到顶部↑
WIKI教程 @2018