{"id":64976,"date":"2025-05-03T17:43:07","date_gmt":"2025-05-03T09:43:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64976\/"},"modified":"2025-05-03T17:43:07","modified_gmt":"2025-05-03T09:43:07","slug":"java-%e6%95%b0%e6%8d%ae%e5%a4%84%e7%90%86%ef%bc%9a%e5%a6%82%e4%bd%95%e5%b0%86%e8%a1%8c%e6%95%b0%e6%8d%ae%e8%bd%ac%e6%8d%a2%e4%b8%ba%e5%88%97%e6%95%b0%e6%8d%ae%ef%bc%9f-3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64976\/","title":{"rendered":"Java \u6570\u636e\u5904\u7406\uff1a\u5982\u4f55\u5c06\u884c\u6570\u636e\u8f6c\u6362\u4e3a\u5217\u6570\u636e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173097885992836.jpg\" class=\"aligncenter\" title=\"Java \u6570\u636e\u5904\u7406\uff1a\u5982\u4f55\u5c06\u884c\u6570\u636e\u8f6c\u6362\u4e3a\u5217\u6570\u636e\uff1f\u63d2\u56fe\" alt=\"Java \u6570\u636e\u5904\u7406\uff1a\u5982\u4f55\u5c06\u884c\u6570\u636e\u8f6c\u6362\u4e3a\u5217\u6570\u636e\uff1f\u63d2\u56fe\" \/><\/p>\n<h2>java \u6570\u636e\u5904\u7406\uff1a\u5b9e\u73b0\u884c\u8f6c\u5217<\/h2>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5982\u4f55\u5c06\u5982\u4e0b\u6e90\u6570\u636e\uff1a<\/p>\n<pre>\u6e90\u6570\u636e\u5982\u4e0b\n\nclass    studentid    subject    score\nclass one    1    english    84\nclass one    1    math    77\nclass one    1    pe    69\nclass one    2    english    81\nclass one    2    math    80\n\u2026    <\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f6c\u6362\u6210\u5982\u4e0b\u671f\u671b\u8f93\u51fa\uff1a<\/p>\n<pre>class    studentid    english    math    pe\nclass one    1    84    77    69<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u884c\u8f6c\u5217\u64cd\u4f5c\uff1a<\/strong><\/p>\n<p>\u4e3a\u4e86\u5c06\u6570\u636e\u4ece\u884c\u8f6c\u4e3a\u5217\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528 java \u7684\u201c\u5206\u7ec4\u201d\u548c\u201c\u805a\u5408\u201d\u64cd\u4f5c\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6839\u636e class \u548c studentid \u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7ec4\uff1a<\/p>\n<pre>import java.util.hashmap;\nimport java.util.list;\nimport java.util.map;\nimport java.util.stream.collectors;\n\npublic class rowtocolumn {\n\n    public static map&lt;string, map&lt;string, list&lt;integer&gt;&gt;&gt; rowtocolumn(list&lt;rowdata&gt; data) {\n        return data.stream()\n            .collect(collectors.groupingby(r -&gt; r.getclass() + \";\" + r.getstudentid(),\n                collectors.groupingby(rowdata::getsubject, collectors.mapping(rowdata::getscore, collectors.tolist()))));\n\n    }\n\n    public static class rowdata {\n        private string class;\n        private string studentid;\n        private string subject;\n        private integer score;\n        \/\/ getters and setters\n    }\n\n    public static void main(string[] args) {\n\n        \/\/ \u521d\u59cb\u5316\u6e90\u6570\u636e\n        list&lt;rowdata&gt; data = new arraylist&lt;&gt;();\n\n        \/\/ ...\n\n        \/\/ \u6267\u884c\u884c\u8f6c\u5217\u64cd\u4f5c\n        map&lt;string, map&lt;string, list&lt;integer&gt;&gt;&gt; result = rowtocolumn(data);\n\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\uff0c\u6211\u4eec\u5bf9\u6bcf\u4e2a\u7ec4\u805a\u5408 subject \u548c score \u5217\uff0c\u5e76\u4f7f\u7528 map \u7ed3\u6784\u6765\u5b58\u50a8\u7ed3\u679c\uff1a<\/p>\n<pre>\/\/ for each group by CLASS + STUDENTID\n\n\/\/ create a new map to store the aggregated data for each SUBJECT\n\n\/\/ for each SUBJECT in the group\n\n\/\/ get the list of SCORES for the SUBJECT in the group\n\n\/\/ add the SUBJECT and the list of SCORES to the map\n\n\/\/ return the map<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u7684 map \u5c06\u5305\u542b\u4ee5 class \u548c studentid \u4f5c\u4e3a\u952e\u7684\u884c\uff0c\u503c\u4e3a subject \u548c score \u7684\u5d4c\u5957 map\u3002<\/p>\n<p>\u901a\u8fc7\u5c06\u884c\u8f6c\u4e3a\u5217\uff0c\u6211\u4eec\u4fbf\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u8bbf\u95ee\u548c\u5904\u7406\u6570\u636e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava \u6570\u636e\u5904\u7406\uff1a\u5982\u4f55\u5c06\u884c\u6570\u636e\u8f6c\u6362\u4e3a\u5217\u6570\u636e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>java \u6570\u636e\u5904\u7406\uff1a\u5b9e\u73b0\u884c\u8f6c\u5217 \u95ee\u9898\uff1a \u5982\u4f55\u5c06\u5982\u4e0b\u6e90\u6570\u636e\uff1a \u6e90\u6570\u636e\u5982\u4e0b class studentid subject score class one 1 english 84 class one 1 math 77 class one 1 pe 69 class one 2 english 81 class one 2 math 80 \u2026 \u767b\u5f55\u540e\u590d\u5236 \u8f6c\u6362\u6210\u5982\u4e0b\u671f\u671b\u8f93\u51fa\uff1a class studentid english math pe class one 1 84 77 69 \u767b\u5f55\u540e\u590d\u5236 \u89e3\u51b3\u65b9\u6848\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u884c\u8f6c\u5217\u64cd\u4f5c\uff1a \u4e3a\u4e86\u5c06\u6570\u636e\u4ece\u884c\u8f6c\u4e3a\u5217\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528 java \u7684\u201c\u5206\u7ec4\u201d\u548c\u201c\u805a\u5408\u201d\u64cd\u4f5c\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-64976","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64976","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=64976"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64976\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}