java中map集合类用法(hashmap用法)

 时间:2024-10-31 19:03:42

1、Map的特性即「键-值」(Key-Value)匹配java.util.HashMap实作了Map界面,HashMap在内部实作使用哈希(Hash),很快的时间内可以寻得「键-值」匹配.2. Map<String, String> map = new HashMap<String, String>(); String key1 = "caterpillar"; String key2 = "justin"; map.put(key1, "caterpillar的讯息"); map.put(key2, "justin的讯息"); System.out.println(map.get(key1)); System.out.println(map.get(key2));

2、可以使用values()方法返回一个实作Collection的对象,当中包括所有的「值」对象. Map<String, String> map = new HashMap<String, String>(); map.put("justin", "justin的讯息"); map.put("momor", "momor的讯息"); map.put("caterpillar", "caterpillar的讯息"); Collection collection = map.values(); Iterator iterator = collection.iterator(); while(iterator.hasNext()) { System.out.println(iterator.next()); } System.out.println();

3、 Map<String, String> map = new LinkedHashMap<String, String>(); map.put("justin", "justin的讯息"); map.put("momor", "momor的讯息"); map.put("caterpillar", "caterpillar的讯息"); for(String value : map.values()) { System.out.println(value); }

  • C#如何使用右键菜单【contextMenuStrip】
  • mysql怎么设置表的操作权限
  • 如何启动weblogic受管理服务器Managed Server
  • sqlplus登录超级用户时提示密码不正确
  • SQLyog设置在编辑器和BLOB查看器中启用自动换行
  • 热门搜索
    怎么煮粥 玉米加农炮怎么用 耳朵进水了怎么办 冻结窗口怎么设置 领带怎么打 一汽奥迪怎么样 颈纹是怎么形成的 主角攻受怎么为我打起来了 大姨妈来了怎么办 怎么查流量