• 2022-05-31
    下面语句执行后,执行get(1)方法得到的值是() HashMap map = new HashMap; map.put(1,"one"); map.put(2,"two"); map.put(3,"three"); map.put(1,"four");
  • 批语

    内容

    • 0

      判断下列程序是否能正常运行,如果能,写出运行结果,如果不能,写出错误原因并进行纠正。import java.util.*;import java.util.Map.*;public class Demo {public static void main(String[] args) {Map map = new HashMap();map.put(1, "Tom");map.put(2, "Lucy");map.put(3,"Annie");Set keySet = map.keySet();Iterator it = keySet.iterator();while (it.hasNext()) {Object key = it.next();System.out.println(key);map.remove(key);}}}

    • 1

      下面创建HashMap的语句中,正确的是 ( )。 A: Map m= new HashMap(); B: HashMap m= new Map(); C: HashMap m=new HashMap<String,String>; D: Map m = new Map();

    • 2

      题示代码的功能为:循环遍历输出Map当中的每一个元素。《插入代码》处应填入的代码是( )Map map=new HashMap(); map.put(“jessica”,100); map.put(“tom”,200); map.put(“den”,300); Set《插入代码1》 set =《插入代码2》; for (《插入代码3》 per : set) { System.out.println(per.getKey() + ":" + per.getValue()); } 未知类型:{'options': ['&#91;Entry&#93; map.keySet() Entry', '&#91;Entry&#93; map.entrySet() Entry', '&#91;Map.Entry<String, Integer&#93;> map.keySet() Map.Entry&#91;String, Integer&#93;', '&#91;Map.Entry<String, Integer&#93;> map.entrySet() Map.Entry&#91;String, Integer&#93;'], 'type': 102}

    • 3

      题示代码的功能为:循环遍历输出Map当中的每一个元素。《插入代码》处应填入的代码是( )Map map=new HashMap(); map.put(“jessica”,100); map.put(“tom”,200); map.put(“den”,300); Set《插入代码1》 set =《插入代码2》; for (《插入代码3》 per : set) { System.out.println(per.getKey() + &quot;:&quot; + per.getValue()); } A: &lt;Entry&gt; map.keySet() Entry B: &lt;Entry&gt; map.entrySet() Entry C: &lt;Map.Entry&lt;String, Integer&gt;&gt; map.keySet() Map.Entry&lt;String, Integer&gt; D: &lt;Map.Entry&lt;String, Integer&gt;&gt; map.entrySet() Map.Entry&lt;String, Integer&gt;

    • 4

      下面创建HashMap的语句中,正确的是 ( )。 A: Map m= new HashMap(); B: HashMap m= new Map(); C: HashMap m=new HashMap&lt;String,String&gt;; D: Map m = new Map();