﻿{"id":974,"date":"2014-06-24T19:37:41","date_gmt":"2014-06-24T11:37:41","guid":{"rendered":"http:\/\/notes.zerobox.org\/?p=974"},"modified":"2016-06-02T19:37:13","modified_gmt":"2016-06-02T11:37:13","slug":"java%e7%a8%8b%e5%ba%8f%e5%91%98%e4%bb%ac%e6%9c%80%e5%b8%b8%e7%8a%af%e7%9a%8410%e4%b8%aa%e9%94%99%e8%af%af","status":"publish","type":"post","link":"http:\/\/zerobox.org\/notes\/974.html","title":{"rendered":"Java\u7a0b\u5e8f\u5458\u4eec\u6700\u5e38\u72af\u768410\u4e2a\u9519\u8bef"},"content":{"rendered":"<p><b style=\"color: #191919;\">\u672c\u6587\u7531\u00a0<a style=\"color: #089bc3;\" href=\"http:\/\/www.importnew.com\/\">ImportNew<\/a>\u00a0&#8211;\u00a0<a style=\"color: #089bc3;\" href=\"http:\/\/www.importnew.com\/author\/onyas\">\u6797\u6797<\/a>\u00a0\u7ffb\u8bd1\u81ea\u00a0<a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/www.programcreek.com\/2014\/05\/top-10-mistakes-java-developers-make\/\" target=\"_blank\" rel=\"nofollow\">programcreek<\/a>\u3002\u6b22\u8fce\u52a0\u5165<a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/www.jobbole.com\/groups\/9\/\" target=\"_blank\" rel=\"nofollow\">Java\u5c0f\u7ec4<\/a>\u3002\u8f6c\u8f7d\u8bf7\u53c2\u89c1\u6587\u7ae0\u672b\u5c3e\u7684\u8981\u6c42\u3002<\/b><\/p>\n<h2 style=\"color: #191919;\">1.\u5c06\u6570\u7ec4\u8f6c\u5316\u4e3a\u5217\u8868<\/h2>\n<p style=\"color: #191919;\">\u5c06\u6570\u7ec4\u8f6c\u5316\u4e3a\u4e00\u4e2a\u5217\u8868\u65f6\uff0c\u7a0b\u5e8f\u5458\u4eec\u7ecf\u5e38\u8fd9\u6837\u505a\uff1a<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_599444\" class=\"syntaxhighlighter notranslate java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\" style=\"color: black !important;\">List&lt;String&gt; list = Arrays.asList(arr);<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\"><code>Arrays.asList()<\/code>\u4f1a\u8fd4\u56de\u4e00\u4e2aArrayList\u5bf9\u8c61\uff0cArrayList\u7c7b\u662fArrays\u7684\u4e00\u4e2a\u79c1\u6709\u9759\u6001\u7c7b\uff0c\u800c\u4e0d\u662fjava.util.ArrayList\u7c7b\uff0cjava.util.Arrays.ArrayList\u7c7b\u6709set()\u3001get()\u3001contains()\u65b9\u6cd5\uff0c\u4f46\u662f\u6ca1\u6709\u589e\u52a0\u5143\u7d20\u7684\u65b9\u6cd5\uff0c\u6240\u4ee5\u5b83\u7684\u5927\u5c0f\u662f\u56fa\u5b9a\u7684\uff0c\u60f3\u8981\u521b\u5efa\u4e00\u4e2a\u771f\u6b63\u7684ArrayList\u7c7b\uff0c\u4f60\u5e94\u8be5\u8fd9\u6837\u505a:<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_643434\" class=\"syntaxhighlighter notranslate java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\" style=\"color: black !important;\">ArrayList&lt;String&gt; arrayList = <\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">new<\/code> <code class=\"java plain\" style=\"color: black !important;\">ArrayList&lt;String&gt;(Arrays.asList(arr));<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\">ArrayList\u7684\u6784\u9020\u65b9\u6cd5\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e2a\u96c6\u5408\u7c7b\u578b\uff0c\u521a\u597d\u5b83\u4e5f\u662fjava.util.Arrays.ArrayList\u7684\u8d85\u7c7b\u3002<\/p>\n<h2 style=\"color: #191919;\">2.\u5224\u65ad\u4e00\u4e2a\u6570\u7ec4\u662f\u5426\u5305\u542b\u4e00\u4e2a\u503c<\/h2>\n<p style=\"color: #191919;\">\u7a0b\u5e8f\u5458\u4eec\u7ecf\u5e38\u8fd9\u6837\u505a:<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_611348\" class=\"syntaxhighlighter notranslate java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\" style=\"color: black !important;\">Set&lt;String&gt; set = <\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">new<\/code> <code class=\"java plain\" style=\"color: black !important;\">HashSet&lt;String&gt;(Arrays.asList(arr));<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java keyword\" style=\"color: #006699 !important;\">return<\/code> <code class=\"java plain\" style=\"color: black !important;\">set.contains(targetValue);<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\">\u8fd9\u6bb5\u4ee3\u7801\u8d77\u4f5c\u7528\uff0c\u4f46\u662f\u6ca1\u6709\u5fc5\u8981\u628a\u4e00\u4e2a\u6570\u7ec4\u8f6c\u5316\u6210\u5217\u8868\uff0c\u8f6c\u5316\u4e3a\u5217\u8868\u9700\u8981\u989d\u5916\u7684\u65f6\u95f4\u3002\u5b83\u53ef\u4ee5\u50cf\u4e0b\u9762\u90a3\u6837\u7b80\u5355:<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_257056\" class=\"syntaxhighlighter notranslate java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\" style=\"color: black !important;\">Arrays.asList(arr).contains(targetValue);<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\">\u6216\u8005\u662f:<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_237082\" class=\"syntaxhighlighter notranslate java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java keyword\" style=\"color: #006699 !important;\">for<\/code><code class=\"java plain\" style=\"color: black !important;\">(String s:arr){<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">if<\/code><code class=\"java plain\" style=\"color: black !important;\">(s.equals(targetValue)){<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">return<\/code> <code class=\"java keyword\" style=\"color: #006699 !important;\">true<\/code><code class=\"java plain\" style=\"color: black !important;\">;<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\" style=\"color: black !important;\">}<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java plain\" style=\"color: black !important;\">}<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java keyword\" style=\"color: #006699 !important;\">return<\/code> <code class=\"java keyword\" style=\"color: #006699 !important;\">false<\/code><code class=\"java plain\" style=\"color: black !important;\">;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\">\u7b2c\u4e00\u79cd\u65b9\u6cd5\u6bd4\u7b2c\u4e8c\u79cd\u66f4\u5bb9\u6613\u8bfb<\/p>\n<h2 style=\"color: #191919;\">3.\u5728\u4e00\u4e2a\u5faa\u73af\u4e2d\u5220\u9664\u4e00\u4e2a\u5217\u8868\u4e2d\u7684\u5143\u7d20<\/h2>\n<p style=\"color: #191919;\">\u601d\u8003\u4e0b\u9762\u8fd9\u4e00\u6bb5\u5728\u5faa\u73af\u4e2d\u5220\u9664\u591a\u4e2a\u5143\u7d20\u7684\u7684\u4ee3\u7801<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_157880\" class=\"syntaxhighlighter notranslate java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\" style=\"color: black !important;\">ArrayList&lt;String&gt; list = <\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">new<\/code> <code class=\"java plain\" style=\"color: black !important;\">ArrayList&lt;String&gt;(Arrays.asList(<\/code><code class=\"java string\" style=\"color: blue !important;\">\"a\"<\/code><code class=\"java plain\" style=\"color: black !important;\">,<\/code><code class=\"java string\" style=\"color: blue !important;\">\"b\"<\/code><code class=\"java plain\" style=\"color: black !important;\">,<\/code><code class=\"java string\" style=\"color: blue !important;\">\"c\"<\/code><code class=\"java plain\" style=\"color: black !important;\">,<\/code><code class=\"java string\" style=\"color: blue !important;\">\"d\"<\/code><code class=\"java plain\" style=\"color: black !important;\">));<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java keyword\" style=\"color: #006699 !important;\">for<\/code><code class=\"java plain\" style=\"color: black !important;\">(<\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">int<\/code> <code class=\"java plain\" style=\"color: black !important;\">i=<\/code><code class=\"java value\" style=\"color: #009900 !important;\">0<\/code><code class=\"java plain\" style=\"color: black !important;\">;i&lt;list.size();i++){<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\" style=\"color: black !important;\">list.remove(i);<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java plain\" style=\"color: black !important;\">}<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java plain\" style=\"color: black !important;\">System.out.println(list);<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\">\u8f93\u51fa\u7ed3\u679c\u662f:<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_777691\" class=\"syntaxhighlighter notranslate shell\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"shell plain\" style=\"color: black !important;\">[b,d]<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\">\u5728\u8fd9\u4e2a\u65b9\u6cd5\u4e2d\u6709\u4e00\u4e2a\u4e25\u91cd\u7684\u9519\u8bef\u3002\u5f53\u4e00\u4e2a\u5143\u7d20\u88ab\u5220\u9664\u65f6\uff0c\u5217\u8868\u7684\u5927\u5c0f\u7f29\u5c0f\u5e76\u4e14\u4e0b\u6807\u53d8\u5316\uff0c\u6240\u4ee5\u5f53\u4f60\u60f3\u8981\u5728\u4e00\u4e2a\u5faa\u73af\u4e2d\u7528\u4e0b\u6807\u5220\u9664\u591a\u4e2a\u5143\u7d20\u7684\u65f6\u5019\uff0c\u5b83\u5e76\u4e0d\u4f1a\u6b63\u5e38\u7684\u751f\u6548\u3002<\/p>\n<p style=\"color: #191919;\">\u4f60\u4e5f\u8bb8\u77e5\u9053\u5728\u5faa\u73af\u4e2d\u6b63\u786e\u7684\u5220\u9664\u591a\u4e2a\u5143\u7d20\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u8fed\u4ee3\uff0c\u5e76\u4e14\u4f60\u77e5\u9053java\u4e2d\u7684foreach\u5faa\u73af\u770b\u8d77\u6765\u50cf\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u4f46\u5b9e\u9645\u4e0a\u5e76\u4e0d\u662f\u3002\u8003\u8651\u4e00\u4e0b\u4e0b\u9762\u7684\u4ee3\u7801:<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_580482\" class=\"syntaxhighlighter notranslate java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\" style=\"color: black !important;\">ArrayList&lt;String&gt; list = <\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">new<\/code> <code class=\"java plain\" style=\"color: black !important;\">ArrayList&lt;String&gt;(Arrays.asList(<\/code><code class=\"java string\" style=\"color: blue !important;\">\"a\"<\/code><code class=\"java plain\" style=\"color: black !important;\">,<\/code><code class=\"java string\" style=\"color: blue !important;\">\"b\"<\/code><code class=\"java plain\" style=\"color: black !important;\">,<\/code><code class=\"java string\" style=\"color: blue !important;\">\"c\"<\/code><code class=\"java plain\" style=\"color: black !important;\">,<\/code><code class=\"java string\" style=\"color: blue !important;\">\"d\"<\/code><code class=\"java plain\" style=\"color: black !important;\">));<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java keyword\" style=\"color: #006699 !important;\">for<\/code><code class=\"java plain\" style=\"color: black !important;\">(String s:list){<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">if<\/code><code class=\"java plain\" style=\"color: black !important;\">(s.equals(<\/code><code class=\"java string\" style=\"color: blue !important;\">\"a\"<\/code><code class=\"java plain\" style=\"color: black !important;\">)){<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\" style=\"color: black !important;\">list.remove(s);<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\" style=\"color: black !important;\">}<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java plain\" style=\"color: black !important;\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\">\u5b83\u4f1a\u629b\u51fa\u4e00\u4e2aConcurrentModificationException\u5f02\u5e38\u3002<br \/>\n\u76f8\u53cd\u4e0b\u9762\u7684\u663e\u793a\u6b63\u5e38\uff1a<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_233832\" class=\"syntaxhighlighter notranslate java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\" style=\"color: black !important;\">ArrayList&lt;String&gt; list = <\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">new<\/code> <code class=\"java plain\" style=\"color: black !important;\">ArrayList&lt;String&gt;(Arrays.asList(<\/code><code class=\"java string\" style=\"color: blue !important;\">\"a\"<\/code><code class=\"java plain\" style=\"color: black !important;\">,<\/code><code class=\"java string\" style=\"color: blue !important;\">\"b\"<\/code><code class=\"java plain\" style=\"color: black !important;\">,<\/code><code class=\"java string\" style=\"color: blue !important;\">\"c\"<\/code><code class=\"java plain\" style=\"color: black !important;\">,<\/code><code class=\"java string\" style=\"color: blue !important;\">\"d\"<\/code><code class=\"java plain\" style=\"color: black !important;\">));<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java plain\" style=\"color: black !important;\">Iterator&lt;String&gt; iter = list.iterator();<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java keyword\" style=\"color: #006699 !important;\">while<\/code><code class=\"java plain\" style=\"color: black !important;\">(iter.hasNext()){<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\" style=\"color: black !important;\">String s = iter.next();<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">if<\/code><code class=\"java plain\" style=\"color: black !important;\">(s.equals(<\/code><code class=\"java string\" style=\"color: blue !important;\">\"a\"<\/code><code class=\"java plain\" style=\"color: black !important;\">)){<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\" style=\"color: black !important;\">iter.remove();<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\" style=\"color: black !important;\">}<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"java plain\" style=\"color: black !important;\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\"><code>.next()<\/code>\u5fc5\u987b\u5728<code>.remove()<\/code>\u4e4b\u524d\u8c03\u7528\u3002\u5728\u4e00\u4e2aforeach\u5faa\u73af\u4e2d\uff0c\u7f16\u8bd1\u5668\u4f1a\u4f7f.next()\u5728\u5220\u9664\u5143\u7d20\u4e4b\u540e\u88ab\u8c03\u7528\uff0c\u56e0\u6b64\u5c31\u4f1a\u629b\u51faConcurrentModificationException\u5f02\u5e38\uff0c\u4f60\u4e5f\u8bb8\u5e0c\u671b\u770b\u4e00\u4e0bArrayList.iterator()\u7684\u6e90\u4ee3\u7801\u3002<\/p>\n<h2 style=\"color: #191919;\">4.Hashtable\u4e0eHashMap\u7684\u5bf9\u6bd4<\/h2>\n<p style=\"color: #191919;\">\u5c31\u7b97\u6cd5\u800c\u8a00\uff0c\u54c8\u5e0c\u8868\u662f\u6570\u636e\u7ed3\u6784\u7684\u4e00\u4e2a\u540d\u5b57\u3002\u4f46\u662f\u5728java\u4e2d\uff0c\u8fd9\u4e2a\u6570\u636e\u7ed3\u6784\u7684\u540d\u5b57\u662fHashMap\u3002Hashtable\u4e0eHashMap\u7684\u4e00\u4e2a\u91cd\u8981\u4e0d\u540c\u70b9\u662fHashtable\u662f\u540c\u6b65\u7684\u3002\u6240\u4ee5\u4f60\u7ecf\u5e38\u4e0d\u9700\u8981Hashtable,\u76f8\u53cdHashMap\u7ecf\u5e38\u4f1a\u7528\u5230\u3002<\/p>\n<p style=\"color: #191919;\"><a style=\"color: #089bc3;\" href=\"http:\/\/www.importnew.com\/8658.html\">HashMap vs. TreeMap vs. Hashtable vs. LinkedHashMap<\/a><\/p>\n<p style=\"color: #191919;\"><a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/www.programcreek.com\/2013\/09\/top-9-questions-for-java-map\/\" target=\"_blank\" rel=\"nofollow\">Top 10 questions about Map<\/a><\/p>\n<h2 style=\"color: #191919;\">5.\u5728\u96c6\u5408\u4e2d\u4f7f\u7528\u539f\u59cb\u7c7b\u578b<\/h2>\n<p style=\"color: #191919;\">\u5728Java\u4e2d\u539f\u59cb\u7c7b\u578b\u4e0e\u65e0\u754c\u901a\u914d\u7b26\u7c7b\u578b\u5f88\u5bb9\u6613\u6df7\u5408\u5728\u4e00\u8d77\uff0c\u62ffSet\u6765\u8bf4\uff0cSet\u662f\u4e00\u4e2a\u539f\u59cb\u7c7b\u578b\uff0c\u800c<code>Set&lt;?&gt;<\/code>\u662f\u65e0\u754c\u7684\u901a\u914d\u7b26\u7c7b\u578b\u3002<br \/>\n\u8003\u8651\u4e0b\u9762\u4f7f\u7528\u539f\u59cb\u7c7b\u578bList\u4f5c\u4e3a\u53c2\u6570\u7684\u4ee3\u7801:<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_858566\" class=\"syntaxhighlighter notranslate java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java keyword\" style=\"color: #006699 !important;\">public<\/code> <code class=\"java keyword\" style=\"color: #006699 !important;\">static<\/code> <code class=\"java keyword\" style=\"color: #006699 !important;\">void<\/code> <code class=\"java plain\" style=\"color: black !important;\">add(List list,Object o){<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\" style=\"color: black !important;\">list.add(o);<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java plain\" style=\"color: black !important;\">}<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java plain\" style=\"color: black !important;\">pulbic <\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">static<\/code> <code class=\"java keyword\" style=\"color: #006699 !important;\">void<\/code> <code class=\"java plain\" style=\"color: black !important;\">main(String[] args){<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\" style=\"color: black !important;\">List&lt;String&gt; list = <\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">new<\/code> <code class=\"java plain\" style=\"color: black !important;\">ArrayList&lt;String&gt;();<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\" style=\"color: black !important;\">add(list,<\/code><code class=\"java value\" style=\"color: #009900 !important;\">10<\/code><code class=\"java plain\" style=\"color: black !important;\">);<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\" style=\"color: black !important;\">String s = list.get(<\/code><code class=\"java value\" style=\"color: #009900 !important;\">0<\/code><code class=\"java plain\" style=\"color: black !important;\">);<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\">\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u629b\u51fa\u4e00\u4e2a\u5f02\u5e38\uff1a<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_646910\" class=\"syntaxhighlighter notranslate shell\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"shell plain\" style=\"color: black !important;\">Exception <\/code><code class=\"shell keyword\" style=\"color: #006699 !important;\">in<\/code> <code class=\"shell plain\" style=\"color: black !important;\">thread <\/code><code class=\"shell string\" style=\"color: blue !important;\">\"main\"<\/code> <code class=\"shell plain\" style=\"color: black !important;\">java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"shell spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"shell plain\" style=\"color: black !important;\">at ...<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\">\u4f7f\u7528\u539f\u751f\u7c7b\u578b\u96c6\u5408\u662f\u5371\u9669\u7684\uff0c\u8fd9\u662f\u56e0\u4e3a\u539f\u751f\u7c7b\u578b\u96c6\u5408\u8df3\u8fc7\u4e86\u6cdb\u578b\u7c7b\u578b\u68c0\u67e5\uff0c\u5e76\u4e14\u4e0d\u662f\u5b89\u5168\u7684\uff0c\u5728<code>Set<\/code>\u3001<code>Set&lt;?&gt;<\/code>\u548cSet<code>&lt;Object&gt;<\/code>\u4e2d\u6709\u5f88\u5927\u7684\u4e0d\u540c\uff0c\u5177\u4f53\u8bf7\u770b<a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/www.programcreek.com\/2013\/12\/raw-type-set-vs-unbounded-wildcard-set\/\" target=\"_blank\" rel=\"nofollow\">Raw type vs. Unbounded wildcard<\/a>\u548c<a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/www.programcreek.com\/2011\/12\/java-type-erasure-mechanism-example\/\" target=\"_blank\" rel=\"nofollow\">Type Erasure<\/a>\u3002<\/p>\n<h2 style=\"color: #191919;\">6.\u8bbf\u95ee\u7ea7\u522b<\/h2>\n<p style=\"color: #191919;\">\u7a0b\u5e8f\u5458\u4eec\u7ecf\u5e38\u4f7f\u7528public\u4f5c\u4e3a\u7c7b\u5b57\u6bb5\u7684\u4fee\u9970\u7b26\uff0c\u53ef\u4ee5\u5f88\u7b80\u5355\u7684\u901a\u8fc7\u5f15\u7528\u5f97\u5230\u503c\uff0c\u4f46\u8fd9\u662f\u4e00\u4e2a\u574f\u7684\u8bbe\u8ba1\uff0c\u6309\u7167\u7ecf\u9a8c\uff0c\u5206\u914d\u7ed9\u6210\u5458\u53d8\u91cf\u7684\u8bbf\u95ee\u7ea7\u522b\u5e94\u8be5\u5c3d\u53ef\u80fd\u7684\u4f4e\u3002<\/p>\n<p style=\"color: #191919;\"><a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/www.programcreek.com\/2011\/11\/java-access-level-public-protected-private\/\" target=\"_blank\" rel=\"nofollow\">public, default, protected, and private<\/a><\/p>\n<h2 style=\"color: #191919;\">7.ArrayList\u4e0eLinkedList\u7684\u5bf9\u6bd4<\/h2>\n<p style=\"color: #191919;\">\u5f53\u7a0b\u5e8f\u5458\u4eec\u4e0d\u77e5\u9053ArrayList\u4e0eLinkedList\u7684\u533a\u522b\u65f6\uff0c\u4ed6\u4eec\u7ecf\u5e38\u4f7f\u7528ArrayList\uff0c\u56e0\u4e3a\u5b83\u770b\u8d77\u6765\u6bd4\u8f83\u719f\u6089\u3002\u7136\u800c\uff0c\u5b83\u4eec\u4e4b\u524d\u6709\u5de8\u5927\u7684\u6027\u80fd\u5dee\u522b\u3002\u7b80\u800c\u8a00\u4e4b\uff0c\u5982\u679c\u6709\u5927\u91cf\u7684\u589e\u52a0\u5220\u9664\u64cd\u4f5c\u5e76\u4e14\u6ca1\u6709\u5f88\u591a\u7684\u968f\u673a\u8bbf\u95ee\u5143\u7d20\u7684\u64cd\u4f5c\uff0c\u5e94\u8be5\u9996\u5148LinkedList\u3002\u5982\u679c\u4f60\u521a\u63a5\u89e6\u5b83\u4eec\uff0c\u8bf7\u67e5\u770b<a style=\"color: #089bc3;\" href=\"http:\/\/www.importnew.com\/12074.html\">ArrayList vs. LinkedList<\/a>\u6765\u83b7\u5f97\u66f4\u591a\u5173\u4e8e\u5b83\u4eec\u6027\u80fd\u7684\u4fe1\u606f\u3002<\/p>\n<h2 style=\"color: #191919;\">8.\u53ef\u53d8\u4e0e\u4e0d\u53ef\u53d8<\/h2>\n<p style=\"color: #191919;\">\u4e0d\u53ef\u53d8\u5bf9\u8c61\u6709\u8bb8\u591a\u7684\u4f18\u70b9\uff0c\u6bd4\u5982\u7b80\u5355\uff0c\u5b89\u5168\u7b49\u7b49\u3002\u4f46\u662f\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u4e0d\u540c\u7684\u503c\u90fd\u9700\u8981\u4e00\u4e2a\u72ec\u7acb\u7684\u5bf9\u8c61\uff0c\u592a\u591a\u7684\u5bf9\u8c61\u53ef\u80fd\u4f1a\u9020\u6210\u5927\u91cf\u7684\u5783\u573e\u56de\u6536\u3002\u5f53\u9009\u62e9\u53ef\u53d8\u4e0e\u4e0d\u53ef\u53d8\u65f6\u5e94\u8be5\u6709\u4e00\u4e2a\u5e73\u8861\u3002<br \/>\n\u4e00\u822c\u7684\uff0c\u53ef\u53d8\u5bf9\u8c61\u7528\u6765\u907f\u514d\u4ea7\u751f\u5927\u91cf\u7684\u4e2d\u95f4\u5bf9\u8c61\u3002\u4e00\u4e2a\u5178\u578b\u7684\u4f8b\u5b50\u662f\u8fde\u63a5\u5927\u91cf\u7684\u5b57\u7b26\u4e32\u3002\u5982\u679c\u4f60\u7528\u4e00\u4e2a\u4e0d\u53ef\u53d8\u7684\u5b57\u7b26\u4e32\uff0c\u4f60\u4f1a\u4ea7\u751f\u5f88\u591a\u9700\u8981\u8fdb\u884c\u5783\u573e\u56de\u6536\u7684\u5bf9\u8c61\u3002\u8fd9\u5f88\u6d6a\u8d39CPU\u7684\u65f6\u95f4\uff0c\u4f7f\u7528\u53ef\u53d8\u5bf9\u8c61\u662f\u6b63\u786e\u7684\u89e3\u51b3\u65b9\u6848(\u6bd4\u5982StringBuilder)\u3002<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_976614\" class=\"syntaxhighlighter notranslate java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\" style=\"color: black !important;\">String result=<\/code><code class=\"java string\" style=\"color: blue !important;\">\"\"<\/code><code class=\"java plain\" style=\"color: black !important;\">;<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java keyword\" style=\"color: #006699 !important;\">for<\/code><code class=\"java plain\" style=\"color: black !important;\">(String s: arr){<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\" style=\"color: black !important;\">result = result + s;<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java plain\" style=\"color: black !important;\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\">\u6709\u65f6\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u4e5f\u662f\u9700\u8981\u53ef\u53d8\u5bf9\u8c61\u7684\uff0c\u6bd4\u5982\u5c06\u53ef\u53d8\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165\u65b9\u6cd5\uff0c\u4f60\u4e0d\u7528\u4f7f\u7528\u5f88\u591a\u8bed\u53e5\u4fbf\u53ef\u4ee5\u5f97\u5230\u591a\u4e2a\u7ed3\u679c\u3002\u53e6\u5916\u4e00\u4e2a\u4f8b\u5b50\u662f\u6392\u5e8f\u548c\u8fc7\u6ee4\uff1a\u5f53\u7136\uff0c\u4f60\u53ef\u4ee5\u5199\u4e00\u4e2a\u65b9\u6cd5\u6765\u63a5\u6536\u539f\u59cb\u7684\u96c6\u5408\uff0c\u5e76\u4e14\u8fd4\u56de\u4e00\u4e2a\u6392\u597d\u5e8f\u7684\u96c6\u5408\uff0c\u4f46\u662f\u90a3\u6837\u5bf9\u4e8e\u5927\u7684\u96c6\u5408\u5c31\u592a\u6d6a\u8d39\u4e86\u3002(\u6765\u81eaStackOverFlow\u7684<a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/stackoverflow.com\/questions\/23616211\/why-we-need-mutable-classes\" target=\"_blank\" rel=\"nofollow\">dasblinkenlight\u2019s\u7684\u7b54\u6848<\/a>)<\/p>\n<p style=\"color: #191919;\"><a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/www.programcreek.com\/2013\/04\/why-string-is-immutable-in-java\/\" target=\"_blank\" rel=\"nofollow\">Why String is Immutable?<\/a><\/p>\n<h2 style=\"color: #191919;\">9.\u7236\u7c7b\u4e0e\u5b50\u7c7b\u7684\u6784\u9020\u51fd\u6570<\/h2>\n<figure class=\"full-width-mobile  thin\" style=\"color: #191919;\"><a style=\"color: #089bc3;\" href=\"http:\/\/www.importnew.com\/?attachment_id=12152\"><img decoding=\"async\" class=\"wp-image-12152\" src=\"http:\/\/notes.zerobox.org\/wp-content\/uploads\/2014\/06\/930b72778379770829f0a1c8671b481f.png\" alt=\"\" \/><\/a><\/figure>\n<p style=\"color: #191919;\">\u8fd9\u4e2a\u7f16\u8bd1\u671f\u9519\u8bef\u7684\u51fa\u73b0\u662f\u7236\u7c7b\u9ed8\u8ba4\u7684\u6784\u9020\u65b9\u6cd5\u672a\u5b9a\u4e49\uff0c\u5728java\u4e2d\uff0c\u5982\u679c\u4e00\u4e2a\u7c7b\u6ca1\u6709\u5b9a\u4e49\u6784\u9020\u65b9\u6cd5\uff0c\u7f16\u8bd1\u5668\u4f1a\u9ed8\u8ba4\u7684\u4e3a\u8fd9\u4e2a\u7c7b\u6dfb\u52a0\u4e00\u4e2a\u65e0\u53c2\u7684\u6784\u9020\u65b9\u6cd5\u3002\u5982\u679c\u5728\u7236\u7c7b\u4e2d\u5b9a\u4e49\u4e86\u6784\u9020\u65b9\u6cd5\uff0c\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\u662fSuper(String s),\u7f16\u8bd1\u5668\u5c31\u4e0d\u4f1a\u6dfb\u52a0\u9ed8\u8ba4\u7684\u65e0\u53c2\u6784\u9020\u65b9\u6cd5\uff0c\u8fd9\u5c31\u662f\u4e0a\u9762\u8fd9\u4e2a\u7236\u7c7b\u7684\u60c5\u5f62\u3002<br \/>\n\u5b50\u7c7b\u7684\u6784\u9020\u5668\uff0c\u4e0d\u7ba1\u662f\u65e0\u53c2\u8fd8\u6709\u6709\u53c2\uff0c\u90fd\u4f1a\u8c03\u7528\u7236\u7c7b\u7684\u65e0\u53c2\u6784\u9020\u5668\u3002\u56e0\u4e3a\u7f16\u8bd1\u5668\u8bd5\u56fe\u5728\u5b50\u7c7b\u7684\u4e24\u4e2a\u6784\u9020\u65b9\u6cd5\u4e2d\u6dfb\u52a0super()\u65b9\u6cd5\u3002\u4f46\u662f\u7236\u7c7b\u9ed8\u8ba4\u7684\u6784\u9020\u65b9\u6cd5\u672a\u5b9a\u4e49\uff0c\u7f16\u8bd1\u5668\u5c31\u4f1a\u62a5\u51fa\u8fd9\u4e2a\u9519\u8bef\u4fe1\u606f\u3002<br \/>\n\u60f3\u8981\u4fee\u590d\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u7b80\u5355\u7684\u901a\u8fc71)\u5728\u7236\u7c7b\u4e2d\u6dfb\u52a0\u4e00\u4e2aSuper()\u6784\u9020\u65b9\u6cd5\uff0c\u50cf\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_743404\" class=\"syntaxhighlighter notranslate java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java keyword\" style=\"color: #006699 !important;\">public<\/code> <code class=\"java plain\" style=\"color: black !important;\">Super(){<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\" style=\"color: black !important;\">System.out.println(<\/code><code class=\"java string\" style=\"color: blue !important;\">\"Super\"<\/code><code class=\"java plain\" style=\"color: black !important;\">);<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java plain\" style=\"color: black !important;\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\">\u6216\u80052)\u79fb\u9664\u7236\u7c7b\u81ea\u5b9a\u4e49\u7684\u6784\u9020\u65b9\u6cd5\uff0c\u6216\u80053)\u5728\u5b50\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u4e2d\u8c03\u7528\u7236\u7c7b\u7684super(value)\u65b9\u6cd5\u3002<\/p>\n<p style=\"color: #191919;\"><a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/www.programcreek.com\/2013\/04\/what-are-the-frequently-asked-questions-about-constructors-in-java\/\" target=\"_blank\" rel=\"nofollow\">Constructor of Super and Stub<\/a><\/p>\n<h2 style=\"color: #191919;\">10.\u201d&#8221;\u8fd8\u662f\u6784\u9020\u5668<\/h2>\n<p style=\"color: #191919;\">\u6709\u4e24\u79cd\u65b9\u5f0f\u53ef\u4ee5\u521b\u5efa\u5b57\u7b26\u4e32<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_291579\" class=\"syntaxhighlighter notranslate java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java comments\" style=\"color: #008200 !important;\">\/\/1.\u4f7f\u7528\u5b57\u7b26\u4e32<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java plain\" style=\"color: black !important;\">String x = <\/code><code class=\"java string\" style=\"color: blue !important;\">\"abc\"<\/code><code class=\"java plain\" style=\"color: black !important;\">;<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java comments\" style=\"color: #008200 !important;\">\/\/2.\u4f7f\u7528\u6784\u9020\u5668<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java plain\" style=\"color: black !important;\">String y = <\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">new<\/code> <code class=\"java plain\" style=\"color: black !important;\">String(<\/code><code class=\"java string\" style=\"color: blue !important;\">\"abc\"<\/code><code class=\"java plain\" style=\"color: black !important;\">);<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\">\u6709\u4ec0\u4e48\u533a\u522b\uff1f<br \/>\n\u4e0b\u9762\u7684\u4f8b\u5b50\u4f1a\u7ed9\u51fa\u4e00\u4e2a\u5feb\u901f\u7684\u7b54\u6848:<\/p>\n<div style=\"color: #191919;\">\n<div id=\"highlighter_973450\" class=\"syntaxhighlighter notranslate java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\" style=\"color: #afafaf !important;\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\" style=\"color: black !important;\">String a = <\/code><code class=\"java string\" style=\"color: blue !important;\">\"abc\"<\/code><code class=\"java plain\" style=\"color: black !important;\">;<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java plain\" style=\"color: black !important;\">String b = <\/code><code class=\"java string\" style=\"color: blue !important;\">\"abc\"<\/code><code class=\"java plain\" style=\"color: black !important;\">;<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java plain\" style=\"color: black !important;\">System.out.println(a==b);<\/code><code class=\"java comments\" style=\"color: #008200 !important;\">\/\/true<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java plain\" style=\"color: black !important;\">System.out.println(a.equals(b));<\/code><code class=\"java comments\" style=\"color: #008200 !important;\">\/\/true<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java plain\" style=\"color: black !important;\">String c = <\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">new<\/code> <code class=\"java plain\" style=\"color: black !important;\">String(<\/code><code class=\"java string\" style=\"color: blue !important;\">\"abc\"<\/code><code class=\"java plain\" style=\"color: black !important;\">);<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java plain\" style=\"color: black !important;\">String d = <\/code><code class=\"java keyword\" style=\"color: #006699 !important;\">new<\/code> <code class=\"java plain\" style=\"color: black !important;\">String(<\/code><code class=\"java string\" style=\"color: blue !important;\">\"abc\"<\/code><code class=\"java plain\" style=\"color: black !important;\">);<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"java plain\" style=\"color: black !important;\">System.out.println(a==b);<\/code><code class=\"java comments\" style=\"color: #008200 !important;\">\/\/false<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"java plain\" style=\"color: black !important;\">System.out.println(a.equals(b));<\/code><code class=\"java comments\" style=\"color: #008200 !important;\">\/\/true<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"color: #191919;\">\u5173\u4e8e\u5b83\u4eec\u5185\u5b58\u5206\u914d\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u8003<a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/www.programcreek.com\/2014\/03\/create-java-string-by-double-quotes-vs-by-constructor\/\" target=\"_blank\" rel=\"nofollow\">Create Java String Using \u201d \u201d or Constructor?.<\/a><\/p>\n<h2 style=\"color: #191919;\">\u5c06\u6765\u7684\u5de5\u4f5c<\/h2>\n<p style=\"color: #191919;\">\u8fd9\u4e2a\u5217\u8868\u662f\u6211\u57fa\u4e8e\u5927\u91cf\u7684github\u4e0a\u7684\u5f00\u6e90\u9879\u76ee\uff0cStack overflow\u4e0a\u7684\u95ee\u9898\uff0c\u8fd8\u6709\u4e00\u4e9b\u6d41\u884c\u7684google\u641c\u7d22\u7684\u5206\u6790\u3002\u6ca1\u6709\u660e\u663e\u793a\u7684\u8bc4\u4f30\u8bc1\u660e\u5b83\u4eec\u662f\u524d10\uff0c\u4f46\u5b83\u4eec\u7edd\u5bf9\u662f\u5f88\u5e38\u89c1\u7684\u3002\u5982\u679c\u60a8\u4e0d\u540c\u610f\u4efb\u4e00\u90e8\u5206\uff0c\u8bf7\u7559\u4e0b\u60a8\u7684\u8bc4\u8bba\u3002\u5982\u679c\u60a8\u80fd\u63d0\u51fa\u5176\u5b83\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\uff0c\u6211\u5c06\u4f1a\u975e\u5e38\u611f\u6fc0\u3002<\/p>\n<h3 style=\"color: #191919;\">\u4f60\u4e5f\u8bb8\u4f1a\u559c\u6b22\u2026<\/h3>\n<p style=\"color: #191919;\">1.<a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/www.programcreek.com\/2013\/04\/what-are-the-frequently-asked-questions-about-constructors-in-java\/\" target=\"_blank\" rel=\"nofollow\">Constructors of Sub and Super Classes in Java?<\/a><\/p>\n<p style=\"color: #191919;\">2.<a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/www.programcreek.com\/2014\/03\/how-developers-sort-in-java\/\" target=\"_blank\" rel=\"nofollow\">How Developers Sort in Java?<\/a><\/p>\n<p style=\"color: #191919;\">3.<a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/www.programcreek.com\/2013\/04\/how-to-convert-array-to-arraylist-in-java\/\" target=\"_blank\" rel=\"nofollow\">How to Convert Array to ArrayList in Java?<\/a><\/p>\n<p style=\"color: #191919;\">4.<a class=\"external\" style=\"color: #089bc3;\" href=\"http:\/\/www.programcreek.com\/2011\/12\/java-type-erasure-mechanism-example\/\" target=\"_blank\" rel=\"nofollow\">Java Type Erasure Mechanism<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u7531\u00a0ImportNew\u00a0&#8211;\u00a0\u6797\u6797\u00a0\u7ffb\u8bd1\u81ea\u00a0programcree &hellip;<\/p>\n<p class=\"read-more\"><a href=\"http:\/\/zerobox.org\/notes\/974.html\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[96],"class_list":["post-974","post","type-post","status-publish","format-standard","hentry","tag-java"],"views":493,"_links":{"self":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/974","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/comments?post=974"}],"version-history":[{"count":0,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/974\/revisions"}],"wp:attachment":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/media?parent=974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/categories?post=974"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/tags?post=974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}