lastKey()%uA0方法用于返回当前在此映射的最后一个(最高)键。
声明
以下是java.util.TreeMap.lastKey()方法的声明。
public K lastKey()
参数
-
NA
返回值
方法调用返回的最后一个(最高)键在这个映射。
异常
-
NoSuchElementException--如果此映射为空,则抛出此异常。
例子
下面的示例演示java.util.TreeMap.lastKey()方法的用法。
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 the last key System.out.println("Checking last key") System.out.println("Value is: "+ treemap.lastKey()) } }
现在编译和运行上面的代码示例,将产生以下结果。
Checking last key Value is: 6