举一反三
- HashMap<Integer,String> map = new HashMap( );map.put(1,"one");map.put(2,"two");map.put(3,"three");map.put(1,"four");
- 19、下列Java程序代码,运行后的结果是( )。[br][/br]...... HashMap map = new HashMap(); map.put("name", Tom); map.put("name", Marry); A: 0 B: C: 1 D: 2
- 应用程序的main方法中有以下语句,则输出的结果是 ( )。 HashMap map=new HashMap(); map.put("100","aaa"); map.put("200","bbb"); map.put("300","ccc"); System.out.println(map.get("300").toString()+ map.get("200").toString() + map.get("100").toString());
- 在Web应用程序中有以下的程序代码,执行后转发到JSP页面Map<String,String> map=new HashMap<String,String>();map.put("key1","String1");map.put("key2","String2");request.setAttribute("user",map);以下选项中的( )可以正确使用EL取得map中的值。 A: ${map.key1} B: ${user.key1} C: ${map["key1"]} D: ${user[key1]}
- 给定如下Java 程序代码片段,编译运行这段代码,结果是( )HashMap map = new HashMap();map.put("name",null);map.put("name","Jack"); System.out.println(map.get("name")); A: null B: Jack C: nullJack D: 运行时出现异常
内容
- 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
题示代码的功能为:循环遍历输出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': ['[Entry] map.keySet() Entry', '[Entry] map.entrySet() Entry', '[Map.Entry<String, Integer]> map.keySet() Map.Entry[String, Integer]', '[Map.Entry<String, Integer]> map.entrySet() Map.Entry[String, Integer]'], 'type': 102}
- 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()); } A: <Entry> map.keySet() Entry B: <Entry> map.entrySet() Entry C: <Map.Entry<String, Integer>> map.keySet() Map.Entry<String, Integer> D: <Map.Entry<String, Integer>> map.entrySet() Map.Entry<String, Integer>
- 3
下面创建HashMap的语句中,正确的是 ( )。 A: Map m= new HashMap(); B: HashMap m= new Map(); C: HashMap m=new HashMap<String,String>; D: Map m = new Map();
- 4
请看一下代码,《插入代码》处应填入的代码是( )Map map=new HashMap(); map.put(“tom”,123.6); map.put(“jim”,234.5); map.put(“terry”,45.3);《插入代码》 其中《插入代码》处要实现的功能是把key为“jim”的value值在原有数字的基础上添加100。 A: map.put(“jim”,map.get(“jim”)+100); B: map.set(“jim”,map.get(“jim”)+100); C: map.put(“jim”,234.5); D: map.set(“jim”,234.5);