集册 Java实例教程 从HashMap获取键的Set视图

从HashMap获取键的Set视图

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

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


import java.util.Iterator;/**n o w  j a v a  . c o m**/

import java.util.HashMap;

import java.util.Set;

 

public class Main {

 

  public static void main(String[] args) {

    HashMap hMap = new HashMap();

   

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

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

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

   

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

   

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


    Iterator itr = st.iterator();

    while(itr.hasNext())

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

     

    st.remove("2");

   

    
展开阅读全文