{"id":35845,"date":"2024-11-26T15:52:53","date_gmt":"2024-11-26T07:52:53","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35845\/"},"modified":"2024-11-26T15:52:53","modified_gmt":"2024-11-26T07:52:53","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8java%e5%b0%86%e4%b8%80%e4%b8%aa%e6%95%b0%e7%bb%84%e6%8c%89%e7%85%a7%e6%8c%87%e5%ae%9a%e5%85%83%e7%b4%a0%e6%8b%86%e5%88%86%e6%88%90%e5%a4%9a%e4%b8%aa%e6%96%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35845\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Java\u5c06\u4e00\u4e2a\u6570\u7ec4\u6309\u7167\u6307\u5b9a\u5143\u7d20\u62c6\u5206\u6210\u591a\u4e2a\u65b0\u6570\u7ec4\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173077632345279.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528Java\u5c06\u4e00\u4e2a\u6570\u7ec4\u6309\u7167\u6307\u5b9a\u5143\u7d20\u62c6\u5206\u6210\u591a\u4e2a\u65b0\u6570\u7ec4\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528Java\u5c06\u4e00\u4e2a\u6570\u7ec4\u6309\u7167\u6307\u5b9a\u5143\u7d20\u62c6\u5206\u6210\u591a\u4e2a\u65b0\u6570\u7ec4\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>java \u6570\u7ec4\u5982\u4f55\u6309\u6307\u5b9a\u5143\u7d20\u62c6\u5206<\/strong><\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4\uff0c\u5982\u4f55\u5c06\u5176\u6309\u7167\u7279\u5b9a\u5143\u7d20\uff08\u4f8b\u5982 85\uff09\u62c6\u5206\u4e3a\u591a\u4e2a\u65b0\u6570\u7ec4\uff1f<\/p>\n<pre>public void mymethod(int[] arr, int splitvalue) {\n    list&lt;list&lt;integer&gt;&gt; result = new arraylist&lt;&gt;();\n    list&lt;integer&gt; temp = new arraylist&lt;&gt;();\n\n    for (int num : arr) {\n        if (num == splitvalue) {\n            if (!temp.isempty()) {\n                result.add(new arraylist&lt;&gt;(temp));\n                temp.clear();\n            }\n            temp.add(num);\n        } else {\n            temp.add(num);\n        }\n    }\n\n    result.add(temp);\n\n    for (list&lt;integer&gt; subarray : result) {\n        system.out.println(arrays.tostring(subarray.toarray()));\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528\u8be5\u65b9\u6cd5\uff1a<\/p>\n<pre>int[] arr = {85, -86, 13, 2, 99, 99, 99, 99, 98, 98, 99, 99, 99, 99, 20, 85, -86, 13, 2, 99, 99, 99, 99, 99, 99, 99, 85, 12, 85, -86, 13, 2, 99};\nmymethod(arr, 85);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>[85, -86, 13, 2, 99, 99, 99, 99, 98, 98, 99, 99, 99, 99, 20]\n[85, -86, 13, 2, 99, 99, 99, 99, 99, 99, 99]\n[85, 12]\n[85, -86, 13, 2, 99]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528Java\u5c06\u4e00\u4e2a\u6570\u7ec4\u6309\u7167\u6307\u5b9a\u5143\u7d20\u62c6\u5206\u6210\u591a\u4e2a\u65b0\u6570\u7ec4\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>java \u6570\u7ec4\u5982\u4f55\u6309\u6307\u5b9a\u5143\u7d20\u62c6\u5206 \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4\uff0c\u5982\u4f55\u5c06\u5176\u6309\u7167\u7279\u5b9a\u5143\u7d20\uff08\u4f8b\u5982 85\uff09\u62c6\u5206\u4e3a\u591a\u4e2a\u65b0\u6570\u7ec4\uff1f public void mymethod(int[] arr, int splitvalue) { list&lt;list&lt;integer&gt;&gt; result = new arraylist&lt;&gt;(); list&lt;integer&gt; temp = new arraylist&lt;&gt;(); for (int num : arr) { if (num == splitvalue) { if (!temp.isempty()) { result.add(new arraylist&lt;&gt;(temp)); temp.clear(); } temp.add(num); } else { temp.add(num); } } result.add(temp); for (list&lt;integer&gt; subarray : result) { system.out.println(arrays.tostring(subarray.toarray())); } [&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-35845","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35845","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=35845"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35845\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}