pollFirstEntry()%uA0方法用于移除并返回最小键在这个映射中的一个键 - 值映射,或者为null相关联,如果映射为空,。
声明
以下是java.util.TreeMap.pollFirstEntry()方法的声明。
public Map.Entry<K,V> pollFirstEntry()
参数
-
NA
返回值
该方法调用返回被移除的第一个条目这个映射中,或null,如果此映射为空。
异常
-
NA
例子
下面的例子显示java.util.TreeMap.pollFirstEntry()方法的使用
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") // polling first entry System.out.println("Value before poll: "+ treemap) System.out.println("Value returned: "+ treemap.pollFirstEntry()) System.out.println("Value after poll: "+ treemap) } }
现在编译和运行上面的代码示例,将产生以下结果。
Value before poll: {1=one, 2=two, 3=three, 5=five, 6=six} Value returned: 1=one Value after poll: {2=two, 3=three, 5=five, 6=six}