集册 Java实例教程 从TreeMap获取密钥集视图

从TreeMap获取密钥集视图

欢马劈雪     最近更新时间:2020-01-02 10:19:05

492
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从TreeMap获取密钥集视图


import java.util.Iterator;// 来 自 时 代 J a v a 公 众 号 - N o w J a v  a . c o m

import java.util.TreeMap;

import java.util.Set;

 

public class Main {

 

  public static void main(String[] args) {

   

    //create TreeMap object

    TreeMap treeMap = new TreeMap();

   

    //add key value pairs to TreeMap

    treeMap.put("1","One");

    treeMap.put("3","Three");

    treeMap.put("2","Two");

   

    Set st = treeMap.keySet();//n o w    j a v a  . c o m

   

    System.out.println("Set created from TreeMap Keys contains :");

   

    Iterator itr = st.iterator();

    while(itr.hasNext())

      System.out.println(itr.next());

     

    //remove 1 from Set

    st.remove("1");

   

    
展开阅读全文