{"id":1835,"date":"2023-08-28T20:38:15","date_gmt":"2023-08-28T12:38:15","guid":{"rendered":"https:\/\/blog.xiunian.wang\/?p=1835"},"modified":"2023-08-28T23:54:05","modified_gmt":"2023-08-28T15:54:05","slug":"kotlin-%e4%b8%ad%e9%81%8d%e5%8e%86list%e7%9a%84n%e7%a7%8d%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/blog.xiunian.wang\/?p=1835","title":{"rendered":"Kotlin \u4e2d\u904d\u5386List\u7684N\u79cd\u65b9\u5f0f"},"content":{"rendered":"\n<p>\u6700\u8fd1\u5f00\u53d1\u4f7f\u7528Kotlin\u786e\u5b9e\u633a\u723d\u7684\uff0c\u5c31\u5728\u4e8e\u8fd9\u95e8\u8bed\u8a00\u8db3\u591f\u73b0\u4ee3\u5316\uff0c\u548cJetBrains\u5bb6\u7684\u7f16\u8f91\u5668\u7ed3\u5408\u8d77\u6765\u66f4\u662f\u65e0\u654c\u4e86\uff0c\u81ea\u52a8\u63d0\u793a\uff0c\u7f16\u8bd1\u4f18\u5316\u90fd\u662f\u5f88\u5b9e\u7528\u7684\uff0c\u4f46\u8fd9\u6837\u57fa\u672c\u4e5f\u8131\u79bb\u4e0d\u4e86\u8fd9\u4e2a\u751f\u6001\u4e86\uff0c\u8bdd\u8bf4\u4eca\u5929\u4f7f\u7528List\u7684\u904d\u5386\uff0c\u5c45\u7136\u6709\u516d\u79cd\u65b9\u5f0f\uff0c\u4f7f\u7528\u54ea\u79cd\u65b9\u5f0f\u90fd\u53ef\u4ee5\u3002\u8fd9\u6837\u867d\u7136\u770b\u8d77\u6765\u5f88\u5e9e\u5927\uff0c\u770b\u8d77\u6765\u5f88\u96be\u8bb0\u7684\u6837\u5b50\uff0c\u4f46\u662f\u597d\u5728\u7f16\u8bd1\u5668+idea\u8db3\u591f\u806a\u660e\uff0c\u8bb0\u4f4f\u4e00\u4e24\u79cd\u5c31OK\u4e86\u3002\u8fd9\u6709\u70b9\u50cf\u662f\u6211\u4eec\u5b66\u4e60\u82f1\u8bed\uff0c\u968f\u7740\u5bf9\u8bed\u4e49\u7684\u66f4\u52a0\u7d27\u51c6\u7684\u8868\u8fbe\uff0c\u82f1\u6587\u5355\u8bcd\u62d3\u5c55\u5230\u4e86\u5341\u51e0\u4e8c\u5341\u4e07\u4e2a\u3002\uff08\u65b9\u4fbf\u7684\u540c\u65f6\u4e5f\u4f1a\u52a0\u5927\u4eba\u4eec\u7684\u8bb0\u5fc6\u8d1f\u62c5\uff09<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u5f0f0<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"kotlin\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"1\" data-enlighter-title=\"\" data-enlighter-group=\"\">    brandList.forEach {\n        println(it)\n    }<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u5f0f1<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"kotlin\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    for (brand in brandList) {\n        println(brand)\n    }<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u5f0f2<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"kotlin\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">  for (index in 0 until brandList.size) {\n        println(\"$index:${brandList[index]}\")\n    }<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u5f0f3<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"kotlin\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    for (index in 0..brandList.lastIndex) {\n        println(\"$index:${brandList[index]}\")\n    }<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u5f0f4<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"kotlin\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    for (index in brandList.indices) {\n        println(\"$index:${brandList[index]}\")\n    }<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u5f0f5<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"kotlin\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    brandList.forEachIndexed { index, brand ->\n        println(\"$index:${brand}\")\n    }<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5f00\u53d1\u4f7f\u7528Kotlin\u786e\u5b9e\u633a\u723d\u7684\uff0c\u5c31\u5728\u4e8e\u8fd9\u95e8\u8bed\u8a00\u8db3\u591f\u73b0\u4ee3\u5316\uff0c\u548cJetBrains\u5bb6\u7684\u7f16\u8f91\u5668\u7ed3\u5408\u8d77\u6765\u66f4\u662f\u65e0\u654c\u4e86\uff0c\u81ea\u52a8\u63d0\u793a\uff0c\u7f16\u8bd1\u4f18\u5316\u90fd\u662f\u5f88\u5b9e\u7528\u7684\uff0c\u4f46\u8fd9\u6837\u57fa\u672c\u4e5f\u8131\u79bb\u4e0d\u4e86\u8fd9\u4e2a\u751f\u6001\u4e86\uff0c\u8bdd\u8bf4\u4eca\u5929\u4f7f\u7528List\u7684\u904d\u5386\uff0c\u5c45\u7136\u6709\u516d\u79cd\u65b9\u5f0f\uff0c\u4f7f\u7528\u54ea\u79cd\u65b9\u5f0f\u90fd\u53ef\u4ee5\u3002\u8fd9\u6837\u867d\u7136\u770b\u8d77\u6765\u5f88\u5e9e\u5927\uff0c\u770b\u8d77\u6765\u5f88\u96be\u8bb0\u7684\u6837\u5b50\uff0c\u4f46\u662f\u597d\u5728\u7f16\u8bd1\u5668+idea\u8db3\u591f\u806a\u660e\uff0c\u8bb0\u4f4f\u4e00\u4e24\u79cd\u5c31OK\u4e86\u3002\u8fd9\u6709\u70b9\u50cf\u662f\u6211\u4eec\u5b66\u4e60\u82f1\u8bed\uff0c\u968f\u7740\u5bf9\u8bed\u4e49\u7684\u66f4\u52a0\u7d27\u51c6\u7684\u8868\u8fbe\uff0c\u82f1\u6587\u5355\u8bcd\u62d3\u5c55\u5230\u4e86\u5341\u51e0\u4e8c\u5341\u4e07\u4e2a\u3002\uff08\u65b9\u4fbf\u7684\u540c\u65f6\u4e5f\u4f1a\u52a0\u5927\u4eba\u4eec\u7684\u8bb0\u5fc6\u8d1f\u62c5\uff09 \u65b9\u5f0f0 \u65b9\u5f0f1 \u65b9\u5f0f2 \u65b9\u5f0f3 \u65b9\u5f0f4 \u65b9\u5f0f5<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[13,28,26],"_links":{"self":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts\/1835"}],"collection":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1835"}],"version-history":[{"count":9,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts\/1835\/revisions"}],"predecessor-version":[{"id":1847,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts\/1835\/revisions\/1847"}],"wp:attachment":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}