提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从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");