{"id":676,"date":"2020-06-22T02:31:38","date_gmt":"2020-06-21T18:31:38","guid":{"rendered":"http:\/\/www.guanhaobo.cn\/?p=676"},"modified":"2020-06-22T02:31:38","modified_gmt":"2020-06-21T18:31:38","slug":"int%e6%95%b0%e7%bb%84%e5%a6%82%e4%bd%95%e8%bd%ac%e6%8d%a2%e6%88%90arraylist","status":"publish","type":"post","link":"https:\/\/www.guanhaobo.cn\/?p=676","title":{"rendered":"int[]\u6570\u7ec4\u5982\u4f55\u8f6c\u6362\u6210ArrayList"},"content":{"rendered":"<pre><code class=\"language-java line-numbers\">import java.util.*;\nimport java.util.stream.*;\n\npublic class Main {\n    public static void main(String[] args) {\n        int[] data = { 4, 5, 3, 6, 2, 5, 1 };\n\n        \/\/ int[] \u8f6c List&lt;Integer&gt;\n        List&lt;Integer&gt; list1 = Arrays.stream(data).boxed().collect(Collectors.toList());\n        \/\/ Arrays.stream(arr) \u53ef\u4ee5\u66ff\u6362\u6210IntStream.of(arr)\u3002\n        \/\/ 1.\u4f7f\u7528Arrays.stream\u5c06int[]\u8f6c\u6362\u6210IntStream\u3002\n        \/\/ 2.\u4f7f\u7528IntStream\u4e2d\u7684boxed()\u88c5\u7bb1\u3002\u5c06IntStream\u8f6c\u6362\u6210Stream&lt;Integer&gt;\u3002\n        \/\/ 3.\u4f7f\u7528Stream\u7684collect()\uff0c\u5c06Stream&lt;T&gt;\u8f6c\u6362\u6210List&lt;T&gt;\uff0c\u56e0\u6b64\u6b63\u662fList&lt;Integer&gt;\u3002\n\n        \/\/ int[] \u8f6c Integer[]\n        Integer[] integers1 = Arrays.stream(data).boxed().toArray(Integer[]::new);\n        \/\/ \u524d\u4e24\u6b65\u540c\u4e0a\uff0c\u6b64\u65f6\u662fStream&lt;Integer&gt;\u3002\n        \/\/ \u7136\u540e\u4f7f\u7528Stream\u7684toArray\uff0c\u4f20\u5165IntFunction&lt;A[]&gt; generator\u3002\n        \/\/ \u8fd9\u6837\u5c31\u53ef\u4ee5\u8fd4\u56deInteger\u6570\u7ec4\u3002\n        \/\/ \u4e0d\u7136\u9ed8\u8ba4\u662fObject[]\u3002\n\n        \/\/ List&lt;Integer&gt; \u8f6c Integer[]\n        Integer[] integers2 = list1.toArray(new Integer[0]);\n        \/\/ \u8c03\u7528toArray\u3002\u4f20\u5165\u53c2\u6570T[] a\u3002\u8fd9\u79cd\u7528\u6cd5\u662f\u76ee\u524d\u63a8\u8350\u7684\u3002\n        \/\/ List&lt;String&gt;\u8f6cString[]\u4e5f\u540c\u7406\u3002\n\n        \/\/ List&lt;Integer&gt; \u8f6c int[]\n        int[] arr1 = list1.stream().mapToInt(Integer::valueOf).toArray();\n        \/\/ \u60f3\u8981\u8f6c\u6362\u6210int[]\u7c7b\u578b\uff0c\u5c31\u5f97\u5148\u8f6c\u6210IntStream\u3002\n        \/\/ \u8fd9\u91cc\u5c31\u901a\u8fc7mapToInt()\u628aStream&lt;Integer&gt;\u8c03\u7528Integer::valueOf\u6765\u8f6c\u6210IntStream\n        \/\/ \u800cIntStream\u4e2d\u9ed8\u8ba4toArray()\u8f6c\u6210int[]\u3002\n\n        \/\/ Integer[] \u8f6c int[]\n        int[] arr2 = Arrays.stream(integers1).mapToInt(Integer::valueOf).toArray();\n        \/\/ \u601d\u8def\u540c\u4e0a\u3002\u5148\u5c06Integer[]\u8f6c\u6210Stream&lt;Integer&gt;\uff0c\u518d\u8f6c\u6210IntStream\u3002\n\n        \/\/ Integer[] \u8f6c List&lt;Integer&gt;\n        List&lt;Integer&gt; list2 = Arrays.asList(integers1);\n        \/\/ \u6700\u7b80\u5355\u7684\u65b9\u5f0f\u3002String[]\u8f6cList&lt;String&gt;\u4e5f\u540c\u7406\u3002\n\n        \/\/ \u540c\u7406\n        String[] strings1 = { \"a\", \"b\", \"c\" };\n        \/\/ String[] \u8f6c List&lt;String&gt;\n        List&lt;String&gt; list3 = Arrays.asList(strings1);\n        \/\/ List&lt;String&gt; \u8f6c String[]\n        String[] strings2 = list3.toArray(new String[0]);\n\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import java.util.*; import java.util.stream.*; public c [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[16],"class_list":["post-676","post","type-post","status-publish","format-standard","hentry","category-note","tag-java"],"_links":{"self":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=676"}],"version-history":[{"count":0,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/676\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}