\u4e94\u3001\u4f7f\u7528StringBuilder \u62fc\u63a5\u5b57\u7b26\u4e32<\/strong><\/div>\n\u4e00\u822c\u7684\u5b57\u7b26\u4e32\u62fc\u63a5\u5728\u7f16\u8bd1\u671fJava \u4f1a\u5bf9\u5176\u8fdb\u884c\u4f18\u5316\uff0c\u4f46\u662f\u5728\u5faa\u73af\u4e2d\u5b57\u7b26\u4e32\u7684\u62fc\u63a5Java \u7f16\u8bd1\u671f\u65e0\u6cd5\u6267\u884c\u4f18\u5316\uff0c\u6240\u4ee5\u9700\u8981\u4f7f\u7528StringBuilder \u8fdb\u884c\u66ff\u6362\u3002<\/p>\n
\u53cd\u4f8b\uff1a<\/p>\n
\r\n \/\/\u5728\u5faa\u73af\u4e2d\u62fc\u63a5\u5b57\u7b26\u4e32\u53cd\u4f8b \r\n String str = \"\"; \r\n for (int i = 0; i < 10; i++){ \r\n \/\/\u5728\u5faa\u73af\u4e2d\u5b57\u7b26\u4e32\u62fc\u63a5Java \u4e0d\u4f1a\u5bf9\u5176\u8fdb\u884c\u4f18\u5316 \r\n str += i; \r\n } \r\n<\/pre>\n\u6b63\u4f8b\uff1a<\/p>\n
\r\n \/\/\u5728\u5faa\u73af\u4e2d\u62fc\u63a5\u5b57\u7b26\u4e32\u6b63\u4f8b \r\n String str1 = \"Love\"; \r\n String str2 = \"Courage\"; \r\n String strConcat = str1 + str2; \/\/Java \u7f16\u8bd1\u5668\u4f1a\u5bf9\u8be5\u666e\u901a\u6a21\u5f0f\u7684\u5b57\u7b26\u4e32\u62fc\u63a5\u8fdb\u884c\u4f18\u5316 \r\n StringBuilder sb = new StringBuilder(); \r\n for (int i = 0; i < 10; i++){ \r\n \/\/\u5728\u5faa\u73af\u4e2d\uff0cJava \u7f16\u8bd1\u5668\u65e0\u6cd5\u8fdb\u884c\u4f18\u5316\uff0c\u6240\u4ee5\u8981\u624b\u52a8\u4f7f\u7528StringBuilder \r\n sb.append(i); \r\n } \r\n<\/pre>\n\u516d\u3001\u82e5\u9700\u9891\u7e41\u8c03\u7528Collection.contains \u65b9\u6cd5\u5219\u4f7f\u7528Set<\/strong><\/div>\n\u5728Java \u96c6\u5408\u7c7b\u5e93\u4e2d\uff0cList\u7684contains \u65b9\u6cd5\u666e\u904d\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(n)\uff0c\u82e5\u4ee3\u7801\u4e2d\u9700\u8981\u9891\u7e41\u8c03\u7528contains \u65b9\u6cd5\u67e5\u627e\u6570\u636e\u5219\u5148\u5c06\u96c6\u5408list \u8f6c\u6362\u6210HashSet \u5b9e\u73b0\uff0c\u5c06O(n) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5c06\u4e3aO(1)\u3002<\/p>\n
\u53cd\u4f8b\uff1a<\/p>\n
\r\n \/\/\u9891\u7e41\u8c03\u7528Collection.contains() \u53cd\u4f8b \r\n List