{"id":317,"date":"2015-11-02T23:17:46","date_gmt":"2015-11-02T20:17:46","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=317"},"modified":"2015-12-15T21:22:14","modified_gmt":"2015-12-15T18:22:14","slug":"java-collections-framework-map-%d0%b7%d0%b0%d0%b4%d0%b0%d1%87%d0%b0-%e2%84%961-%d1%87%d0%b0%d1%81%d1%82%d0%be%d1%82%d0%bd%d1%8b%d0%b9-%d1%81%d0%bb%d0%be%d0%b2%d0%b0%d1%80%d1%8c","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=317","title":{"rendered":"Java Collections Framework: Map. \u0427\u0430\u0441\u0442\u043e\u0442\u043d\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c."},"content":{"rendered":"<h2>\u0417\u0430\u0434\u0430\u0447\u0430 1:<\/h2>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u043a\u043e\u0440\u043f\u0443\u0441 \u044f\u0437\u044b\u043a\u0430 (\u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u043d\u0430 \u043a\u0430\u043a\u043e\u043c-\u043d\u0438\u0431\u0443\u0434\u044c \u044f\u0437\u044b\u043a\u0435) \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0447\u0430\u0441\u0442\u043e\u0442\u043d\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c. \u0417\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f, \u0441\u043a\u043e\u0431\u043a\u0438, \u043a\u0430\u0432\u044b\u0447\u043a\u0438 \u0438 \u0447\u0438\u0441\u043b\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0443\u0434\u0430\u043b\u0435\u043d\u044b. \u0421\u043b\u043e\u0432\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0432 \u0441\u0435\u0431\u0435 \u043d\u0435 \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b, \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0446\u0435\u043b\u0438\u043a\u043e\u043c.<\/p>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430 2:<\/h2>\n<p>\u041f\u0440\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u043b\u043e\u0432 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 (Set) \u0441\u043b\u043e\u0432-\u043a\u043b\u044e\u0447\u0435\u0439, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442 \u0442\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p><pre class=\"lang:java decode:true \">\r\nimport java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\n \r\n\/* Name of the class has to be \"Main\" only if the class is public. *\/\r\nclass Ideone\r\n{\r\n\tpublic static void main (String[] args) throws java.lang.Exception\r\n\t{\r\n                \/\/\u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c\r\n\t\tMap W = new HashMap();\r\n\t\tScanner in = new Scanner(System.in);\r\n\t\tString txt = new String();\r\n\t\tlong all = 0;\r\n \r\n\t\tin.useDelimiter(\"[,.!:;? \\n\u00ab\u00bb()\\\"]\");\r\n\t\twhile(in.hasNext()){\r\n\t\t\ttxt = in.next();\r\n\t\t\t\tif(!txt.equals(\"\"))\r\n\t\t\t\t\tif(W.containsKey(txt)){ W.put(txt, W.get(txt) + 1.0); all++;} \r\n\t\t\t\t\telse{ W.put(txt, 1.0); all++;} \r\n\t\t}\r\n \r\n \r\n \r\n\t\tfor(String a : W.keySet())  W.put(a, W.get(a)\/all);\r\n \r\n                \/\/\u0411\u043e\u043d\u0443\u0441\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c (\u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0435 \u0442\u044f\u043d\u0435\u0442, \u043d\u043e \u0432\u0441\u0435 \u0436\u0435)\r\n                \/\/\u0412\u043c\u0435\u0441\u0442\u043e \u0441\u043b\u043e\u0432, \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0441\u043b\u0443\u0436\u0430\u0442 \u0447\u0430\u0441\u0442\u043e\u0442\u044b.\r\n                \/\/\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043b\u043e\u0432 \u0441 \u043e\u0431\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439 \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u044f\r\n\r\n\t\tSortedMap&lt;Double, List&gt; SW = new TreeMap&lt;Double, List&gt;();\r\n \r\n\t\tfor(Object a : W.keySet()) \r\n\t\t\tif(SW.containsKey(W.get(a))){\r\n\t\t\t\tSW.get(W.get(a)).add(a);\r\n\t\t\t}\r\n\t\t\telse{\r\n\t\t\t\tList buf = new ArrayList();\r\n\t\t\t\tbuf.add(a);\r\n\t\t\t\tSW.put(W.get(a), buf) ;\r\n\t\t\t}\r\n \r\n\t\tfor(Object a : SW.keySet()){\r\n\t\t\tSystem.out.print(a + \" =&gt; \" );\r\n\t\t\tint n = SW.get(a).size();\r\n\t\t\tfor(int i = 0; i &lt; n; i++){\r\n\t\t\t\tSystem.out.print(SW.get(a).get(i) + (i == n - 1? &quot;.\\n&quot; : &quot;, &quot;));\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<p><a href=\"https:\/\/ideone.com\/oLRCtD\"> <strong>\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 Ideone<\/strong><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 1: \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u043a\u043e\u0440\u043f\u0443\u0441 \u044f\u0437\u044b\u043a\u0430 (\u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u043d\u0430 \u043a\u0430\u043a\u043e\u043c-\u043d\u0438\u0431\u0443\u0434\u044c \u044f\u0437\u044b\u043a\u0435) \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0447\u0430\u0441\u0442\u043e\u0442\u043d\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c. \u0417\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f, \u0441\u043a\u043e\u0431\u043a\u0438, \u043a\u0430\u0432\u044b\u0447\u043a\u0438 \u0438 \u0447\u0438\u0441\u043b\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0443\u0434\u0430\u043b\u0435\u043d\u044b. \u0421\u043b\u043e\u0432\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0432 \u0441\u0435\u0431\u0435 \u043d\u0435 \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b, \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0446\u0435\u043b\u0438\u043a\u043e\u043c. \u0417\u0430\u0434\u0430\u0447\u0430 2: \u041f\u0440\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u043b\u043e\u0432 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=317\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":23,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/317"}],"collection":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=317"}],"version-history":[{"count":6,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/317\/revisions"}],"predecessor-version":[{"id":331,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/317\/revisions\/331"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}