{"id":89,"date":"2022-01-31T21:19:13","date_gmt":"2022-01-31T21:19:13","guid":{"rendered":"https:\/\/liangqi.org\/?p=89"},"modified":"2022-02-03T14:09:42","modified_gmt":"2022-02-03T14:09:42","slug":"%e4%b8%80%e4%ba%9b%e9%9d%a2%e8%af%95%e7%ae%97%e6%b3%95%e4%b8%ad%e7%9a%84java%e5%9f%ba%e6%9c%ac%e6%93%8d%e4%bd%9c%e8%bf%90%e7%ae%97","status":"publish","type":"post","link":"https:\/\/liangqi.org\/?p=89","title":{"rendered":"\u4e00\u4e9b\u9762\u8bd5\u7b97\u6cd5\u4e2d\u7684Java\u57fa\u672c\u64cd\u4f5c\u8fd0\u7b97"},"content":{"rendered":"\n<p>\u5f88\u4e45\u6ca1\u6709\u771f\u7684\u5199\u7a0b\u5e8f\uff0c\u4e00\u4e9b\u57fa\u672c\u7684Utils\u7684\u4f7f\u7528\u4e5f\u6de1\u5fd8\u4e86\u3002\u8fd9\u91cc\u603b\u7ed3\u4e00\u4e0b:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u6570\u7ec4\">\u6570\u7ec4<\/h2>\n\n\n\n<p>\u6570\u7ec4\u8f6c\u5316\u6210List<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Convert a two dimension to a List. Array is an object in Java. So we can do it.\nList&lt;int&#91;]&gt; a = Arrays.asList(intervals);\n\n\/\/ One dimension\n\/\/ https:\/\/www.techiedelight.com\/convert-int-array-list-integer\/\nint&#91;] bb= {1,3,4,5};\n        List&lt;Integer&gt; ddd = Arrays.stream(bb).boxed().collect(Collectors.toList());\n\/\/Or we can just use Integer array:\nInteger&#91;] cc = {1,3,4,5};\nList&lt;Integer&gt; rrr = Arrays.asList( cc );<\/code><\/pre>\n\n\n\n<p>List\u8f6c\u5316\u4e3a\u6570\u7ec4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>new ArrayList&lt;&gt;().toArray(new String&#91;length]);\n\n\/\/Two dimension array. List of an array\nList&lt;int&#91;]&gt; list;\/\/&#91;&#91;1,2],&#91;3,5]]\nlist.toArray(new int&#91;list.size()]&#91;]);<\/code><\/pre>\n\n\n\n<p>\u6392\u5e8f\u6570\u7ec4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Sort a two dimension array by the first element in each array ite.\n\/\/ &#91;&#91;1,2],&#91;5,6],&#91;3,4]].  --&gt; &#91;&#91;1,2],&#91;3,4],&#91;5,6]\nArrays.sort(intervals, (a,b) -&gt; Integer.compare(a&#91;0],b&#91;0])); <\/code><\/pre>\n\n\n\n<p>\u6392\u5e8fList<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Collections.sort(list);<\/code><\/pre>\n\n\n\n<p>\u6253\u5370\u4e00\u7ef4\u6570\u7ec4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u552f\u4e00\u4e0d\u597d\u6253\u5370\u7684\u5c31\u662f\u6570\u7ec4\uff0cList\u548cMap\u90fd\u53ef\u4ee5\u76f4\u63a5\u6253\u5370\nSystem.out.println(Arrays.toString({1,3,4,5});<\/code><\/pre>\n\n\n\n<p>\u6253\u5370\u591a\u4e8e\u4e00\u7ef4\u6570\u7ec4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int&#91;]&#91;] abc = {{1,2},{2,5},{5,9};\nSystem.out.println(Arrays.deepToString(abc}; \/\/\u5b57\u9762\u91cf\u4e0d\u80fd\u76f4\u63a5\u4f7f\u7528. And please note that the deepToString cannot be used to an array.<\/code><\/pre>\n\n\n\n<p>\u6253\u5370List<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>list.forEach(System.out::println);\n\/\/Actually 'list' can be print directly. The format is &#91;d,w]<\/code><\/pre>\n\n\n\n<p>\u7b54\u5e94list\u91cc\u9762\u542b\u6709array<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>list.forEach( (item) -&gt; System.out.println(Arrays.toString(item)));<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"map\">MAP<\/h3>\n\n\n\n<p>Merge<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Adding 1 for the key\nmap.merge(\"key\", 1, (old, new1) -&gt; old + new1); \n\/\/Sum\nmap.merge(\"key\", 3, Integer::sum);<\/code><\/pre>\n\n\n\n<p>Print a map<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Actually map can be print directly. the format {a=b,a2=b3}\nmap.forEach( (key,value) -&gt; System.out.println(\"key:\" + key + \"value:\"+value));\nmap.keySet().forEach( (key) -&gt; XXX );\nmap.values().forEACH( (value) -&gt; XXX);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5176\u4ed6\">\u5176\u4ed6<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Objects.requireNotNull(param);<\/code><\/pre>\n\n\n\n<p>boolean\u7684\u503c\u53ea\u80fd\u662ftrue\uff0cfalse\uff0c\u800c\u4e0d\u80fd\u662f0\uff0c1.<\/p>\n\n\n\n<p>char\u662f\u7528\u5355\u5f15\u53f7: char abc=&#8217;a&#8217;;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f88\u4e45\u6ca1\u6709\u771f\u7684\u5199\u7a0b\u5e8f\uff0c\u4e00\u4e9b\u57fa\u672c\u7684Utils\u7684\u4f7f\u7528\u4e5f\u6de1\u5fd8\u4e86\u3002\u8fd9\u91cc\u603b\u7ed3\u4e00\u4e0b: \u6570\u7ec4 \u6570\u7ec4\u8f6c\u5316\u6210List List\u8f6c\u5316\u4e3a\u6570\u7ec4 \u6392\u5e8f\u6570\u7ec4 \u6392\u5e8fList \u6253\u5370\u4e00\u7ef4\u6570\u7ec4 \u6253\u5370\u591a\u4e8e\u4e00\u7ef4\u6570\u7ec4 \u6253\u5370List \u7b54\u5e94list\u91cc\u9762\u542b\u6709array MAP Merge Print a map \u5176\u4ed6 boolean\u7684\u503c\u53ea\u80fd\u662ftrue\uff0cfalse\uff0c\u800c\u4e0d\u80fd\u662f0\uff0c1. char\u662f\u7528\u5355\u5f15\u53f7: char abc=&#8217;a&#8217;;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,17],"tags":[],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-16","category-17"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4e00\u4e9b\u9762\u8bd5\u7b97\u6cd5\u4e2d\u7684Java\u57fa\u672c\u64cd\u4f5c\u8fd0\u7b97 - Liangqi\u2018s Technical Journey<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/liangqi.org\/?p=89\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4e00\u4e9b\u9762\u8bd5\u7b97\u6cd5\u4e2d\u7684Java\u57fa\u672c\u64cd\u4f5c\u8fd0\u7b97 - Liangqi\u2018s Technical Journey\" \/>\n<meta property=\"og:description\" content=\"\u5f88\u4e45\u6ca1\u6709\u771f\u7684\u5199\u7a0b\u5e8f\uff0c\u4e00\u4e9b\u57fa\u672c\u7684Utils\u7684\u4f7f\u7528\u4e5f\u6de1\u5fd8\u4e86\u3002\u8fd9\u91cc\u603b\u7ed3\u4e00\u4e0b: \u6570\u7ec4 \u6570\u7ec4\u8f6c\u5316\u6210List List\u8f6c\u5316\u4e3a\u6570\u7ec4 \u6392\u5e8f\u6570\u7ec4 \u6392\u5e8fList \u6253\u5370\u4e00\u7ef4\u6570\u7ec4 \u6253\u5370\u591a\u4e8e\u4e00\u7ef4\u6570\u7ec4 \u6253\u5370List \u7b54\u5e94list\u91cc\u9762\u542b\u6709array MAP Merge Print a map \u5176\u4ed6 boolean\u7684\u503c\u53ea\u80fd\u662ftrue\uff0cfalse\uff0c\u800c\u4e0d\u80fd\u662f0\uff0c1. char\u662f\u7528\u5355\u5f15\u53f7: char abc=&#8217;a&#8217;;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/liangqi.org\/?p=89\" \/>\n<meta property=\"og:site_name\" content=\"Liangqi\u2018s Technical Journey\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-31T21:19:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-03T14:09:42+00:00\" \/>\n<meta name=\"author\" content=\"liangqi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"liangqi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/liangqi.org\/?p=89#article\",\"isPartOf\":{\"@id\":\"https:\/\/liangqi.org\/?p=89\"},\"author\":{\"name\":\"liangqi\",\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"headline\":\"\u4e00\u4e9b\u9762\u8bd5\u7b97\u6cd5\u4e2d\u7684Java\u57fa\u672c\u64cd\u4f5c\u8fd0\u7b97\",\"datePublished\":\"2022-01-31T21:19:13+00:00\",\"dateModified\":\"2022-02-03T14:09:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/liangqi.org\/?p=89\"},\"wordCount\":20,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"articleSection\":[\"\u6280\u672f\",\"\u7b97\u6cd5\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/liangqi.org\/?p=89#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/liangqi.org\/?p=89\",\"url\":\"https:\/\/liangqi.org\/?p=89\",\"name\":\"\u4e00\u4e9b\u9762\u8bd5\u7b97\u6cd5\u4e2d\u7684Java\u57fa\u672c\u64cd\u4f5c\u8fd0\u7b97 - Liangqi\u2018s Technical Journey\",\"isPartOf\":{\"@id\":\"https:\/\/liangqi.org\/#website\"},\"datePublished\":\"2022-01-31T21:19:13+00:00\",\"dateModified\":\"2022-02-03T14:09:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/liangqi.org\/?p=89#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/liangqi.org\/?p=89\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/liangqi.org\/?p=89#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/liangqi.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4e00\u4e9b\u9762\u8bd5\u7b97\u6cd5\u4e2d\u7684Java\u57fa\u672c\u64cd\u4f5c\u8fd0\u7b97\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/liangqi.org\/#website\",\"url\":\"https:\/\/liangqi.org\/\",\"name\":\"Liangqi\u2018s Technical Journey\",\"description\":\"Chasing Excellence; Enjoy life.\",\"publisher\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/liangqi.org\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\",\"name\":\"liangqi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg\",\"contentUrl\":\"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg\",\"width\":2560,\"height\":1920,\"caption\":\"liangqi\"},\"logo\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/liangqi.org\"],\"url\":\"https:\/\/liangqi.org\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4e00\u4e9b\u9762\u8bd5\u7b97\u6cd5\u4e2d\u7684Java\u57fa\u672c\u64cd\u4f5c\u8fd0\u7b97 - Liangqi\u2018s Technical Journey","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/liangqi.org\/?p=89","og_locale":"en_US","og_type":"article","og_title":"\u4e00\u4e9b\u9762\u8bd5\u7b97\u6cd5\u4e2d\u7684Java\u57fa\u672c\u64cd\u4f5c\u8fd0\u7b97 - Liangqi\u2018s Technical Journey","og_description":"\u5f88\u4e45\u6ca1\u6709\u771f\u7684\u5199\u7a0b\u5e8f\uff0c\u4e00\u4e9b\u57fa\u672c\u7684Utils\u7684\u4f7f\u7528\u4e5f\u6de1\u5fd8\u4e86\u3002\u8fd9\u91cc\u603b\u7ed3\u4e00\u4e0b: \u6570\u7ec4 \u6570\u7ec4\u8f6c\u5316\u6210List List\u8f6c\u5316\u4e3a\u6570\u7ec4 \u6392\u5e8f\u6570\u7ec4 \u6392\u5e8fList \u6253\u5370\u4e00\u7ef4\u6570\u7ec4 \u6253\u5370\u591a\u4e8e\u4e00\u7ef4\u6570\u7ec4 \u6253\u5370List \u7b54\u5e94list\u91cc\u9762\u542b\u6709array MAP Merge Print a map \u5176\u4ed6 boolean\u7684\u503c\u53ea\u80fd\u662ftrue\uff0cfalse\uff0c\u800c\u4e0d\u80fd\u662f0\uff0c1. char\u662f\u7528\u5355\u5f15\u53f7: char abc=&#8217;a&#8217;;","og_url":"https:\/\/liangqi.org\/?p=89","og_site_name":"Liangqi\u2018s Technical Journey","article_published_time":"2022-01-31T21:19:13+00:00","article_modified_time":"2022-02-03T14:09:42+00:00","author":"liangqi","twitter_card":"summary_large_image","twitter_misc":{"Written by":"liangqi","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/liangqi.org\/?p=89#article","isPartOf":{"@id":"https:\/\/liangqi.org\/?p=89"},"author":{"name":"liangqi","@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"headline":"\u4e00\u4e9b\u9762\u8bd5\u7b97\u6cd5\u4e2d\u7684Java\u57fa\u672c\u64cd\u4f5c\u8fd0\u7b97","datePublished":"2022-01-31T21:19:13+00:00","dateModified":"2022-02-03T14:09:42+00:00","mainEntityOfPage":{"@id":"https:\/\/liangqi.org\/?p=89"},"wordCount":20,"commentCount":0,"publisher":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"articleSection":["\u6280\u672f","\u7b97\u6cd5"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/liangqi.org\/?p=89#respond"]}]},{"@type":"WebPage","@id":"https:\/\/liangqi.org\/?p=89","url":"https:\/\/liangqi.org\/?p=89","name":"\u4e00\u4e9b\u9762\u8bd5\u7b97\u6cd5\u4e2d\u7684Java\u57fa\u672c\u64cd\u4f5c\u8fd0\u7b97 - Liangqi\u2018s Technical Journey","isPartOf":{"@id":"https:\/\/liangqi.org\/#website"},"datePublished":"2022-01-31T21:19:13+00:00","dateModified":"2022-02-03T14:09:42+00:00","breadcrumb":{"@id":"https:\/\/liangqi.org\/?p=89#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/liangqi.org\/?p=89"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/liangqi.org\/?p=89#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/liangqi.org\/"},{"@type":"ListItem","position":2,"name":"\u4e00\u4e9b\u9762\u8bd5\u7b97\u6cd5\u4e2d\u7684Java\u57fa\u672c\u64cd\u4f5c\u8fd0\u7b97"}]},{"@type":"WebSite","@id":"https:\/\/liangqi.org\/#website","url":"https:\/\/liangqi.org\/","name":"Liangqi\u2018s Technical Journey","description":"Chasing Excellence; Enjoy life.","publisher":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/liangqi.org\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3","name":"liangqi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/liangqi.org\/#\/schema\/person\/image\/","url":"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg","contentUrl":"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg","width":2560,"height":1920,"caption":"liangqi"},"logo":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/liangqi.org"],"url":"https:\/\/liangqi.org\/?author=1"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=89"}],"version-history":[{"count":12,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":158,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions\/158"}],"wp:attachment":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}