asp 绿色环保企业网站源码 v1.1,重庆建网站培训机构,网站建设用自助建站系统好不好,网站备案后可以更换域名吗java.util.TreeMap.lastKey()用于检索Map中存在的最后一个或最高键。用法:tree_map.lastKey()参数#xff1a;该方法不带任何参数。返回值#xff1a;该方法返回映射中存在的最后一个键。异常#xff1a;如果映射为空#xff0c;则该方法将引发NoSuchElementException。以下…java.util.TreeMap.lastKey()用于检索Map中存在的最后一个或最高键。用法:tree_map.lastKey()参数该方法不带任何参数。返回值该方法返回映射中存在的最后一个键。异常如果映射为空则该方法将引发NoSuchElementException。以下程序说明了java.util.TreeMap.lastKey()方法的用法示例1:// Java code to illustrate the lastKey() methodimport java.util.*;public class Tree_Map_Demo {public static void main(String[] args){// Creating an empty TreeMapTreeMap tree_map new TreeMap();// Mapping string values to int keystree_map.put(10, Geeks);tree_map.put(15, 4);tree_map.put(20, Geeks);tree_map.put(25, Welcomes);tree_map.put(30, You);// Displaying the TreeMapSystem.out.println(The Mappings are: tree_map);// Displaying the lastKey of the mapSystem.out.println(The last key is tree_map.lastKey());}}输出The Mappings are: {10Geeks, 154, 20Geeks, 25Welcomes, 30You}The last key is 30示例2:// Java code to illustrate the lastKey() methodimport java.util.*;public class Tree_Map_Demo {public static void main(String[] args){// Creating an empty TreeMapTreeMap tree_map new TreeMap();// Mapping int values to string keystree_map.put(Geeks, 10);tree_map.put(4, 15);tree_map.put(Geeks, 20);tree_map.put(Welcomes, 25);tree_map.put(You, 30);// Displaying the TreeMapSystem.out.println(The Mappings are: tree_map);// Displaying the lastKey of the mapSystem.out.println(The last key is tree_map.lastKey());}}输出The Mappings are: {415, Geeks20, Welcomes25, You30}The last key is You