{"id":641,"date":"2011-09-14T17:26:25","date_gmt":"2011-09-14T09:26:25","guid":{"rendered":"http:\/\/www.hawkwithwind.net\/blog\/?p=641"},"modified":"2011-09-14T17:31:12","modified_gmt":"2011-09-14T09:31:12","slug":"%e5%a4%8d%e5%90%88%e5%8a%9f%e8%83%bd%e5%b0%b1%e6%98%af%e4%bb%a3%e7%a0%81%e5%9d%8f%e5%91%b3","status":"publish","type":"post","link":"https:\/\/www.hawkwithwind.net\/blog\/2011\/09\/14\/%e5%a4%8d%e5%90%88%e5%8a%9f%e8%83%bd%e5%b0%b1%e6%98%af%e4%bb%a3%e7%a0%81%e5%9d%8f%e5%91%b3\/","title":{"rendered":"\u590d\u5408\u529f\u80fd\u5c31\u662f\u4ee3\u7801\u574f\u5473"},"content":{"rendered":"<p>\u8fd9\u53e5\u8bdd\u8981\u53cd\u590d\u91cd\u590d\u7ed9\u81ea\u5df1\u542c\u3002<br \/>\n\u4eca\u5929\u5728\u770bjava\u7684\u5b98\u65b9\u6587\u6863\u7684\u65f6\u5019\u770b\u5230\u4e86\u8fd9\u4e48\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"java\">\r\nList suits = ...;\r\nList ranks = ...;\r\nList sortedDeck = new ArrayList();\r\n\r\n\/\/ BROKEN - throws NoSuchElementException!\r\nfor (Iterator i = suits.iterator(); i.hasNext(); )\r\n    for (Iterator j = ranks.iterator(); j.hasNext(); )\r\n        sortedDeck.add(new Card(i.next(), j.next()));\r\n<\/code><\/pre>\n<p>\u6587\u6863\u4e2d\u4e3e\u8fd9\u4e2a\u4f8b\u5b50\u662f\u4e3a\u4e86\u63a8\u5e7fforeach\u8bed\u53e5\u7684\u4f7f\u7528\u3002\u4f46\u5728\u6211\u770b\u6765\uff0c\u4e4b\u6240\u4ee5\u5bb9\u6613\u4ea7\u751f\u8fd9\u6837\u7684\u9519\u8bef\uff0c\u539f\u56e0\u662fjava\u7684iterator\u7684\u65b9\u6cd5\u4e0d\u591f\u5185\u805a\u3002<\/p>\n<h3>\u4e3a\u4ec0\u4e48\u8981\u7528iterator.next()\u8fd4\u56deiterator\u6307\u5411\u7684\u503c?<\/h3>\n<p>\u8fd9\u8ba9\u6211\u60f3\u8d77\u4e86C++\u7684STL\u4e2d\u4e00\u7cfb\u5217\u5173\u4e8e\u5806\u6808\u7684\u64cd\u4f5c\u3002\u83b7\u53d6\u6808\u9876\u7684\u65b9\u6cd5\u662fback()\u6216front()\uff0c\u51fa\u6808\u7684\u65b9\u6cd5\u662fpop_front()\u6216pop_back()\u3002\u662f\u8fd9\u6837\u505a\uff0c\u800c\u4e0d\u662f\u4ee4pop_back()\u76f4\u63a5\u8fd4\u56de\u6808\u9876\u503c\u540c\u65f6\u5f39\u51fa\u3002\u8fd9\u5c31\u4fdd\u8bc1\u4e86\u51fd\u6570\u65b9\u6cd5\u7684\u7edd\u5bf9\u5185\u805a\u3002\u4ece\u800c\u907f\u514d\u4e86\u5982\u540c\u524d\u4f8b\u90a3\u6837\u7684\u6f5c\u5728\u9519\u8bef\u3002<\/p>\n<p>\u6c38\u8fdc\u4fdd\u8bc1\u81ea\u5df1\u7684\u51fd\u6570\u529f\u80fd\u5355\u4e00\uff0c\u6ca1\u6709\u526f\u4f5c\u7528\u3002\u4e0d\u8981\u7528\u5c0f\u6280\u5de7\u53bb\u8ba9\u4e00\u4e2a\u51fd\u6570\u591a\u529f\u80fd\u5316\u3002\u6709\u65f6\u5019\u6f5c\u5728\u7684\u9519\u8bef\u8fdc\u8fdc\u4e0d\u662f\u4e00\u773c\u80fd\u770b\u5f97\u51fa\u6765\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u53e5\u8bdd\u8981\u53cd\u590d\u91cd\u590d\u7ed9\u81ea\u5df1\u542c\u3002 \u4eca\u5929\u5728\u770bjava\u7684\u5b98\u65b9\u6587\u6863\u7684\u65f6\u5019\u770b\u5230\u4e86\u8fd9\u4e48\u4e00\u4e2a\u4f8b\u5b50\uff1a List suits = &#8230;; List ranks = &#8230;; List sortedDeck = new ArrayList(); \/\/ BROKEN &#8211; throws NoSuchElementException! for (Iterator i = suits.iterator(); i.hasNext(); ) for (Iterator j = ranks.iterator(); j.hasNext(); ) sortedDeck.add(new Card(i.next(), j.next())); \u6587\u6863\u4e2d\u4e3e\u8fd9\u4e2a\u4f8b\u5b50\u662f\u4e3a\u4e86\u63a8\u5e7fforeach\u8bed\u53e5\u7684\u4f7f\u7528\u3002\u4f46\u5728\u6211\u770b\u6765\uff0c\u4e4b\u6240\u4ee5\u5bb9\u6613\u4ea7\u751f\u8fd9\u6837\u7684\u9519\u8bef\uff0c\u539f\u56e0\u662fjava\u7684iterator\u7684\u65b9\u6cd5\u4e0d\u591f\u5185\u805a\u3002 \u4e3a\u4ec0\u4e48\u8981\u7528iterator.next()\u8fd4\u56deiterator\u6307\u5411\u7684\u503c? \u8fd9\u8ba9\u6211\u60f3\u8d77\u4e86C++\u7684STL\u4e2d\u4e00\u7cfb\u5217\u5173\u4e8e\u5806\u6808\u7684\u64cd\u4f5c\u3002\u83b7\u53d6\u6808\u9876\u7684\u65b9\u6cd5\u662fback()\u6216front()\uff0c\u51fa\u6808\u7684\u65b9\u6cd5\u662fpop_front()\u6216pop_back()\u3002\u662f\u8fd9\u6837\u505a\uff0c\u800c\u4e0d\u662f\u4ee4pop_back()\u76f4\u63a5\u8fd4\u56de\u6808\u9876\u503c\u540c\u65f6\u5f39\u51fa\u3002\u8fd9\u5c31\u4fdd\u8bc1\u4e86\u51fd\u6570\u65b9\u6cd5\u7684\u7edd\u5bf9\u5185\u805a\u3002\u4ece\u800c\u907f\u514d\u4e86\u5982\u540c\u524d\u4f8b\u90a3\u6837\u7684\u6f5c\u5728\u9519\u8bef\u3002 \u6c38\u8fdc\u4fdd\u8bc1\u81ea\u5df1\u7684\u51fd\u6570\u529f\u80fd\u5355\u4e00\uff0c\u6ca1\u6709\u526f\u4f5c\u7528\u3002\u4e0d\u8981\u7528\u5c0f\u6280\u5de7\u53bb\u8ba9\u4e00\u4e2a\u51fd\u6570\u591a\u529f\u80fd\u5316\u3002\u6709\u65f6\u5019\u6f5c\u5728\u7684\u9519\u8bef\u8fdc\u8fdc\u4e0d\u662f\u4e00\u773c\u80fd\u770b\u5f97\u51fa\u6765\u7684\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[35],"class_list":["post-641","post","type-post","status-publish","format-standard","hentry","category-note","tag-35"],"_links":{"self":[{"href":"https:\/\/www.hawkwithwind.net\/blog\/wp-json\/wp\/v2\/posts\/641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hawkwithwind.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hawkwithwind.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hawkwithwind.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hawkwithwind.net\/blog\/wp-json\/wp\/v2\/comments?post=641"}],"version-history":[{"count":4,"href":"https:\/\/www.hawkwithwind.net\/blog\/wp-json\/wp\/v2\/posts\/641\/revisions"}],"predecessor-version":[{"id":645,"href":"https:\/\/www.hawkwithwind.net\/blog\/wp-json\/wp\/v2\/posts\/641\/revisions\/645"}],"wp:attachment":[{"href":"https:\/\/www.hawkwithwind.net\/blog\/wp-json\/wp\/v2\/media?parent=641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hawkwithwind.net\/blog\/wp-json\/wp\/v2\/categories?post=641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hawkwithwind.net\/blog\/wp-json\/wp\/v2\/tags?post=641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}