size()%uA0方法用来返回在此映射的键 - 值映射关系的数量。
声明
以下是java.util.TreeMap.size()方法的声明。
public int size()
参数
-
NA
返回值
该方法调用返回此映射中的键 - 值映射关系的数量。
异常
-
NA
例子
下面的例子显示java.util.TreeMap.size()方法的使用
package com.yiibai import java.util.* public class TreeMapDemo { public static void main(String[] args) { // creating tree map TreeMap<Integer, String> treemap = new TreeMap<Integer, String>() // populating tree map treemap.put(2, "two") treemap.put(1, "one") treemap.put(3, "three") treemap.put(6, "six") treemap.put(5, "five") // getting size of the map System.out.println("Size of the map: "+treemap.size()) } }
现在编译和运行上面的代码示例,将产生以下结果。
Size of the map: 5