目录

Map.Entry<K,V> pollLastEntry()

描述 (Description)

pollLastEntry()方法用于删除和返回与此映射中的最大键关联的键 - 值映射,如果映射为空,则返回null。

声明 (Declaration)

以下是java.util.TreeMap.pollLastEntry()方法的声明。

public Map.Entry<K,V> pollLastEntry()

参数 (Parameters)

NA

返回值 (Return Value)

方法调用返回此映射的已删除的最后一个条目,如果此映射为空,则返回null。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.util.TreeMap.pollLastEntry()的用法

package com.iowiki;
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 last entry
      System.out.println("Value before poll: "+ treemap);            
      System.out.println("Value returned: "+ treemap.pollLastEntry());      
      System.out.println("Value after poll: "+ treemap);
   }    
}

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

Value before poll: {1=one, 2=two, 3=three, 5=five, 6=six}
Value returned: 6=six
Value after poll: {1=one, 2=two, 3=three, 5=five}
↑回到顶部↑
WIKI教程 @2018