{"id":232,"date":"2017-01-17T16:00:00","date_gmt":"2017-01-17T07:00:00","guid":{"rendered":"https:\/\/java-code.jp\/?p=232"},"modified":"2017-01-17T16:00:11","modified_gmt":"2017-01-17T07:00:11","slug":"hashmap","status":"publish","type":"post","link":"https:\/\/java-code.jp\/232","title":{"rendered":"HashMap"},"content":{"rendered":"<p><em class=\"ccenterContents01\">\u30ad\u30fc\uff0f\u5024\u306e\u30da\u30a2\u3092\u8868\u3059\u30de\u30c3\u30d7 &#8211; HashMap\u30af\u30e9\u30b9<\/em><\/p>\n<p>\u30de\u30c3\u30d7\u306f\u3001\u30ea\u30b9\u30c8\u3084\u30bb\u30c3\u30c8\u3001\u30ad\u30e5\u30fc\u3068\u7570\u306a\u308a\u3001\u30ad\u30fc\u3068\u5024\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u8981\u7d20\u3092\u7ba1\u7406\u3057\u307e\u3059\u3002HashMap\u306f\u3001\u30de\u30c3\u30d7\u306e\u5b9f\u88c5\u30af\u30e9\u30b9\u306e\u4e2d\u3067\u3082\u6700\u3082\u57fa\u672c\u7684\u306a\u30af\u30e9\u30b9\u3067\u3059\u3002\u30ad\u30fc\u306f\u91cd\u8907\u3067\u304d\u305a\u3001\u307e\u305f\u9806\u756a\u3092\u6301\u3061\u307e\u305b\u3093\u3002<br \/>\n  HashMap\u30af\u30e9\u30b9\u3067\u5229\u7528\u3067\u304d\u308b\u30e1\u30bd\u30c3\u30c9\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<table>\n<tbody>\n<tr>\n<th colspan=\"2\" class=\"tableTitle\">HashMap\u30af\u30e9\u30b9\u306e\u4e3b\u306a\u30e1\u30bd\u30c3\u30c9<\/th>\n<\/tr>\n<tr>\n<th>\u30e1\u30bd\u30c3\u30c9<\/th>\n<th>\u6982\u8981<\/th>\n<\/tr>\n<tr>\n<td>clear()<\/td>\n<td>\u3059\u3079\u3066\u306e\u8981\u7d20\u3092\u524a\u9664<\/td>\n<\/tr>\n<tr>\n<td>containsKey(Object key)<\/td>\n<td>\u30ad\u30fckey\u304c\u30de\u30c3\u30d7\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3092\u5224\u5b9a<\/td>\n<\/tr>\n<tr>\n<td>containsValue(Object value)<\/td>\n<td>\u5024value\u304c\u30de\u30c3\u30d7\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3092\u5224\u5b9a<\/td>\n<\/tr>\n<tr>\n<td>get(Object key)<\/td>\n<td>\u30ad\u30fckey\u306b\u5bfe\u5fdc\u3059\u308b\u5024\u3092\u53d6\u5f97<\/td>\n<\/tr>\n<tr>\n<td>isEmpty()<\/td>\n<td>\u30de\u30c3\u30d7\u304c\u7a7a\u304b\u3092\u5224\u5b9a<\/td>\n<\/tr>\n<tr>\n<td>keySet()<\/td>\n<td>\u3059\u3079\u3066\u306e\u30ad\u30fc\u3092\u53d6\u5f97<\/td>\n<\/tr>\n<tr>\n<td>put(K key, V value)<\/td>\n<td>\u6307\u5b9a\u3055\u308c\u305f\u30ad\u30fc\uff0f\u5024\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u8ffd\u52a0<\/td>\n<\/tr>\n<tr>\n<td>remove(Object key)<\/td>\n<td>\u6307\u5b9a\u306e\u30ad\u30fc\u3092\u524a\u9664<\/td>\n<\/tr>\n<tr>\n<td>int size()<\/td>\n<td>\u30de\u30c3\u30d7\u306e\u8981\u7d20\u6570\u3092\u53d6\u5f97<\/td>\n<\/tr>\n<tr>\n<td>Collection&lt;V&gt; values()<\/td>\n<td>\u3059\u3079\u3066\u306e\u5024\u3092\u53d6\u5f97<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4ee5\u4e0b\u306f\u3001HashMap\u306b\u8981\u7d20\u3092\u30bb\u30c3\u30c8\u3057\u3001\u305d\u306e\u30ad\u30fc\uff0f\u5024\u3092\u9806\u306b\u51fa\u529b\u3059\u308b\u4f8b\u3067\u3059\u3002<\/p>\n<p class=\"list\">CollMap.java<\/p>\n<div class=\"pre\">\n<pre class=\"brush:java;highlight:[8,39];\">\r\npackage com.example.mynavi.collection;\r\n\r\nimport java.util.HashMap;\r\nimport java.util.Map;\r\n\r\npublic class CollMap {\r\n  public static void main(String[] args) {\r\n    Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;() {\r\n      {\r\n        put(\"\u30d1\u30bd\u30b3\u30f3\", \"personal computer\");\r\n        put(\"\u30a8\u30a2\u30b3\u30f3\", \"air conditioner\");\r\n        put(\"\u30ea\u30e2\u30b3\u30f3\", \"remote control\");\r\n      }\r\n    };\r\n\r\n    for (String str : map.keySet()) {\r\n      System.out.println(str + \":\" + map.get(str));\r\n\t\/\/ \u7d50\u679c\uff1a\u30a8\u30a2\u30b3\u30f3:air conditioner\u3001\u30d1\u30bd\u30b3\u30f3:personal computer\u3001\u30ea\u30e2\u30b3\u30f3:remote control\r\n    }\r\n\r\n    for (String val : map.values()) {\r\n      System.out.println(val + \":\" + map.get(val));\r\n\t\/\/ \u7d50\u679c\uff1aair conditioner\u3001personal computer\u3001remote control\r\n    }\r\n\r\n    System.out.println(map.containsKey(\"\u30a8\u30a2\u30b3\u30f3\"));\t\/\/ \u7d50\u679c\uff1atrue\r\n    System.out.println(map.containsValue(\"tourconductor\"));\t\/\/ \u7d50\u679c\uff1afalse\r\n\r\n    if (!map.isEmpty()) {\r\n      System.out.println(\"\u8981\u7d20\u6570\u306f\" + map.size() + \"\u500b\u3067\u3059\u3002\");\r\n\t\/\/ \u7d50\u679c\uff1a\u8981\u7d20\u6570\u306f3\u500b\u3067\u3059\u3002\r\n    }\r\n\r\n    map.remove(\"\u30d1\u30bd\u30b3\u30f3\");\r\n    System.out.println(map);\r\n\t\/\/ \u7d50\u679c\uff1a{\u30a8\u30a2\u30b3\u30f3=air conditioner, \u30ea\u30e2\u30b3\u30f3=remote control}\r\n\r\n    map.clear();\r\n    System.out.println(map);\t\/\/ \u7d50\u679c\uff1a{}\r\n  }\r\n}\r\n<\/pre>\n<p><!-- \/ .pre --><\/div>\n<p>HashMap\u3067\u306f\u3001\u30ad\u30fc\u3092\u7ba1\u7406\u3059\u308b\u305f\u3081\u306b\u5185\u90e8\u7684\u306b\u300c\u30cf\u30c3\u30b7\u30e5\u8868\u300d\u3068\u547c\u3070\u308c\u308b\u914d\u5217\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u3002\u8981\u7d20\u3092\u633f\u5165\u3059\u308b\u969b\u306b\u3082\u3001\u307e\u305a\u306f\u3001\u30ad\u30fc\u304b\u3089\u30cf\u30c3\u30b7\u30e5\u5024\u3092\u6c42\u3081\u3001\u305d\u306e\u5024\u306b\u57fa\u3065\u3044\u3066\u3001\u30cf\u30c3\u30b7\u30e5\u8868\u306e\u3069\u3053\u306b\u8981\u7d20\u3092\u633f\u5165\u3059\u308b\u304b\u3092\u6c7a\u3081\u308b\u308f\u3051\u3067\u3059\u3002<br \/>\n  \u305d\u306e\u6027\u8cea\u4e0a\u3001HashMap\u3092\u5229\u7528\u3059\u308b\u5834\u5408\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u70b9\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>  <em class=\"ccenterContents02\">\uff081\uff09equals\uff0fhashCode\u30e1\u30bd\u30c3\u30c9\u306f\u307e\u3068\u3081\u3066\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3059\u308b<\/em><\/p>\n<p>HashMap\u3067\u306f\u3001\u30cf\u30c3\u30b7\u30e5\u5024\u3092\u6c42\u3081\u308b\u305f\u3081\u306bhashCode\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002\u305d\u3057\u3066\u3001hashCode\u30e1\u30bd\u30c3\u30c9\u306f\u300c\u7b49\u4fa1\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u540c\u58eb\u3067\u306f\u3001\u540c\u3058\u5024\u3092\u8fd4\u3059\u300d\u3068\u3044\u3046\u30eb\u30fc\u30eb\u304c\u3042\u308a\u307e\u3059\u3002equals\u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u305f\uff08\uff1d\u7b49\u4fa1\u30eb\u30fc\u30eb\u3092\u5909\u66f4\u3057\u305f\uff09\u5834\u5408\u306b\u306f\u3001\u5fc5\u305ahashCode\u30e1\u30bd\u30c3\u30c9\u3082\u307e\u3068\u3081\u3066\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>  <em class=\"ccenterContents02\">\uff082\uff09\u30cf\u30c3\u30b7\u30e5\u8868\u306e\u30b5\u30a4\u30ba\u3092\u9069\u5207\u306b\u8a2d\u5b9a\u3059\u308b<\/em><\/p>\n<p>\u30ad\u30fc\u306e\u30cf\u30c3\u30b7\u30e5\u5024\u304c\u91cd\u8907\u3057\u305f\u5834\u5408\u3001HashMap\u306f\u305d\u306e\u8981\u7d20\u3092\u30ea\u30f3\u30af\u30ea\u30b9\u30c8\u3068\u3057\u3066\u7ba1\u7406\u3057\u307e\u3059\u3002\u30ea\u30f3\u30af\u30ea\u30b9\u30c8\u306f\u691c\u7d22\u52b9\u7387\u306f\u826f\u304f\u306a\u3044\u30c7\u30fc\u30bf\u69cb\u9020\u306a\u306e\u3067\u3001\u30cf\u30c3\u30b7\u30e5\u5024\u304c\u91cd\u8907\u3059\u308c\u3070\u3059\u308b\u307b\u3069\u3001HashMap\u306e\u691c\u7d22\u52b9\u7387\u305d\u306e\u3082\u306e\u304c\u4f4e\u4e0b\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<br \/>\n  \u305d\u306e\u305f\u3081\u3001HashMap\u3067\u306f\u8981\u7d20\u306e\u500b\u6570\u304c\u30cf\u30c3\u30b7\u30e5\u8868\u306b\u5bfe\u3057\u3066\u4e00\u5b9a\u5272\u5408\u3092\u8d85\u3048\u308b\u3068\u3001\u30cf\u30c3\u30b7\u30e5\u8868\u305d\u306e\u3082\u306e\u3092\u62e1\u5f35\u3057\u3088\u3046\u3068\u3057\u307e\u3059\u3002ArrayList\u3067\u3082\u89e6\u308c\u305f\u3088\u3046\u306b\u3001\u914d\u5217\uff08\u30cf\u30c3\u30b7\u30e5\u8868\uff09\u306e\u518d\u5272\u308a\u5f53\u3066\u306f\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u306e\u9ad8\u3044\u51e6\u7406\u3067\u3059\u3002\u3088\u3063\u3066\u3001\u3042\u3089\u304b\u3058\u3081\u683c\u7d0d\u3059\u3079\u304d\u8981\u7d20\u306e\u500b\u6570\u304c\u4e88\u6e2c\u3067\u304d\u3066\u3044\u308b\u306a\u3089\u3070\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u306b\u969b\u3057\u3066\u3001\u30b5\u30a4\u30ba\u3092\u5ba3\u8a00\u3057\u3066\u304a\u304f\u3079\u304d\u3067\u3059\u3002<\/p>\n<div class=\"pre\">\n<pre class=\"brush:java;highlight:[1];\">\r\nMap&lt;String,String&gt; map = new HashMap&lt;String,String&gt;(20);\r\n<\/pre>\n<p><!-- \/ .pre --><\/div>\n<p> \u30cf\u30c3\u30b7\u30e5\u8868\u30b5\u30a4\u30ba\u306e\u521d\u671f\u5024\u306f16\u3067\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u305d\u306e75\uff05\uff0812\u500b\uff09\u3092\u8d85\u3048\u305f\u3068\u3053\u308d\u3067\u3001\u30cf\u30c3\u30b7\u30e5\u8868\u306e\u62e1\u5f35\u304c\u5b9f\u65bd\u3055\u308c\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30ad\u30fc\uff0f\u5024\u306e\u30da\u30a2\u3092\u8868\u3059\u30de\u30c3\u30d7 &#8211; HashMap\u30af\u30e9\u30b9 \u30de\u30c3\u30d7\u306f\u3001\u30ea\u30b9\u30c8\u3084\u30bb\u30c3\u30c8\u3001\u30ad\u30e5\u30fc\u3068\u7570\u306a\u308a\u3001\u30ad\u30fc\u3068\u5024\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u8981\u7d20\u3092\u7ba1\u7406\u3057\u307e\u3059\u3002HashMap\u306f\u3001\u30de\u30c3\u30d7\u306e\u5b9f\u88c5\u30af\u30e9\u30b9\u306e\u4e2d\u3067\u3082\u6700\u3082\u57fa\u672c\u7684\u306a\u30af\u30e9\u30b9\u3067\u3059\u3002\u30ad\u30fc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-232","post","type-post","status-publish","format-standard","hentry","category-frame"],"_links":{"self":[{"href":"https:\/\/java-code.jp\/wp-json\/wp\/v2\/posts\/232"}],"collection":[{"href":"https:\/\/java-code.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java-code.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java-code.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/java-code.jp\/wp-json\/wp\/v2\/comments?post=232"}],"version-history":[{"count":7,"href":"https:\/\/java-code.jp\/wp-json\/wp\/v2\/posts\/232\/revisions"}],"predecessor-version":[{"id":1091,"href":"https:\/\/java-code.jp\/wp-json\/wp\/v2\/posts\/232\/revisions\/1091"}],"wp:attachment":[{"href":"https:\/\/java-code.jp\/wp-json\/wp\/v2\/media?parent=232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java-code.jp\/wp-json\/wp\/v2\/categories?post=232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java-code.jp\/wp-json\/wp\/v2\/tags?post=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}