java split如何把单词作为分隔符来分割字符?
Java\uff1a\u4e3a\u4ec0\u4e48\u4f7f\u7528split\u5206\u9694\u5b57\u7b26\u4e32\u65f6\uff0c\u5206\u9694"?"\u5b57\u7b26\u9700\u8981\u5199\u6210[?]\u5462\uff1f\u56e0\u4e3a\u67e5\u770bapi\uff0c\u4f60\u5c31\u4f1a\u53d1\u73b0String.split(String regex)\uff0c\u4e5f\u5c31\u662f\u8bf4\u91cc\u9762\u7684\u53c2\u6570\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\u3002
\u5982\u679c\u662f\u4e00\u4e9b\u666e\u901a\u7684\u5b57\u7b26\uff0c\u5b83\u5c31\u4f1a\u5f53\u505a\u666e\u901a\u5b57\u7b26\u7ed9\u62c6\u5206\u5b57\u7b26\u4e32\u3002\u53ef\u662f ?\u662f\u7279\u6b8a\u5b57\u7b26\uff0c\u60f3\u8ba9\u6309\u7167 \u5b83\u6765\u5206\uff0c\u6240\u4ee5\u5c31\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u8868\u793a\u67d0\u4e2a\u7279\u5b9a\u5b57\u7b26\u7684\u65b9\u5f0f\u4e86\u3002
\u4e5f\u5c31\u662f\u8bf4[?] \u5c31\u8868\u793a \u95ee\u53f7
1\u3001Java\u662f\u4e00\u79cd\u53ef\u4ee5\u64b0\u5199\u8de8\u5e73\u53f0\u5e94\u7528\u7a0b\u5e8f\u7684\u9762\u5411\u5bf9\u8c61\u7684\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u3002Java \u6280\u672f\u5177\u6709\u5353\u8d8a\u7684\u901a\u7528\u6027\u3001\u9ad8\u6548\u6027\u3001\u5e73\u53f0\u79fb\u690d\u6027\u548c\u5b89\u5168\u6027\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8ePC\u3001\u6570\u636e\u4e2d\u5fc3\u3001\u6e38\u620f\u63a7\u5236\u53f0\u3001\u79d1\u5b66\u8d85\u7ea7\u8ba1\u7b97\u673a\u3001\u79fb\u52a8\u7535\u8bdd\u548c\u4e92\u8054\u7f51\uff0c\u540c\u65f6\u62e5\u6709\u5168\u7403\u6700\u5927\u7684\u5f00\u53d1\u8005\u4e13\u4e1a\u793e\u7fa4\u3002
2\u3001Java\u7684\u4e3b\u8981\u5de5\u4f5c\uff1a\u901a\u8fc7\u7f16\u7a0b\u8bed\u8a00\u6765\u5236\u4f5c\u4e92\u8054\u7f51\u9875\u9762\u3001\u5236\u4f5c\u52a8\u6001\u6548\u679c\u4ee5\u53ca\u7f51\u7ad9\u7b49\u6280\u672f\uff0c\u73b0\u5728\u7f51\u4e0a\u5173\u4e8e\u8fd9\u65b9\u9762\u7684\u6559\u7a0b\u6709\u5f88\u591a\uff0c\u4f46\u5f88\u591a\u90fd\u662f\u8fc7\u65f6\u7684\uff0c\u56e0\u4e3a\u4e92\u8054\u7f51\u662f\u5728\u4e0d\u65ad\u7684\u53d8\u5316\u7684\uff0c\u4e92\u8054\u7f51\u4e0a\u7684\u725b\u4eba\uff0c\u8981\u60f3\u6210\u4e3aJava\u5927\u795e\uff0c\u8d70\u8fdb\u8fd9\u6761Java\u5927\u795e\u4e4b\u7fa4\uff0c\u9996\u5148Java\u6559\u7a0b\u7684\u5f00\u5934\u662f\u4e8c\u4e09\u4e00\uff0cJava\u7684\u6700\u4e2d\u95f4\u662f\u4e09\u4e00\u56db\uff0cJava\u7684\u6700\u540e\u9762\u518d\u52a0\u4e0a\u96f6\u4e8c\u516b\uff0c\u628a\u524d\u9762\u7684\u7efc\u5408\u8d77\u6765\uff0cJava\u5927\u795e\u671f\u5f85\u4f60\u7684\u52a0\u5165\u3002
|\u5728java\u6b63\u5219\u8868\u8fbe\u5f0f\u5c31\u662f\u4e00\u4e2a\u7279\u6b8a\u5b57\u7b26\u3002
\\u5728Java\u5b57\u7b26\u4e32\u662f\u7279\u6b8a\u5b57\u7b26\u3002
\u6240\u4ee5\|\u662f\u4e0d\u80fd\u8868\u8fbe\u666e\u901a\u5b57\u7b26|\u5728split()\u65b9\u6cd5\u7684\u3002
\u53ea\u80fd\u8f6c\u4e492\u6b21
-----------------------------------
\u76f8\u4fe1\u697c\u4e0a2\u4f4d\u8fdeJava\u6b63\u5219\u8868\u8fbe\u5f0f \u8fd9\u4e2a\u672f\u8bed\u90fd\u6ca1\u542c\u8bf4\u8fc7\u5427\uff01\u90a3String.split()\u65b9\u6cd5\u7684\u53c2\u6570\u4f60\u4eec\u4e0d\u61c2\u4e5f\u5c31\u4e0d\u4e3a\u5947\u4e86\uff01
-----------------------------------\u300b
\ \u5728Java\u4e2d\u4e13\u95e8\u7528\u6765\u8f6c\u4e49\u5b57\u7b26\u7528\u7684(\u52a1\u5fc5\u7262\u8bb0\uff1a\\u7684\u4f5c\u7528\u662f\u628a\u7d27\u8ddf\u5176\u540e\u4e00\u4e2a\u5b57\u7b26\u8f6c\u4e49)
\u7f16\u8f91\u5668\u8bc6\u522b\u7684\u6807\u51c6\u8f6c\u4e49\u5b57\u7b26\uff1a
\b \t \n \f \r \" \' \\
\u975e\u6807\u51c6\u8f6c\u4e49\u5b57\u7b26\u7684\u573a\u5408\uff0c\u9700\u8981\u4f7f\u7528 \\ \u6765\u8f85\u52a9\u8f6c\u4e49
\u5176\u5b9e\uff0cLZ\u91c7\u7528\u5206\u5272\u7b26\u4e3a"|"\uff0c\u8fd9\u79cd\u7528\u6cd5\u662f\u5927\u5fcc\u554a
String.split\u65b9\u6cd5\uff0c\u91c7\u7528\u7684\u662fJava\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u5206\u5272\u5b57\u7b26\u4e32(\u53c2\u89c1javadoc)
\u56e0\u6b64\u614e\u7528\u7279\u6b8a\u5b57\u7b26\u554a
String.split\u65b9\u6cd5(\u4ee5\u53ca\u5176\u5b83\u7c7b\u4f3c\u7684\u9700\u8981\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u573a\u5408)
\u5e38\u89c1\u7684\u9700\u8981\u56de\u907f\u201c\u627e\u62bd\u201d\u7684\u5b57\u7b26\u6709\uff1a , \ | ^ * + ? ( ) { } [ ] \u7b49\u7b49
\u5982\u679c\u5b9e\u5728\u60f3\u7528\u7684\u8bdd\uff0c\u5728split\u4e4b\u7c7b\u9700\u8981\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5730\u65b9\uff0c\u5fc5\u987b\u91c7\u7528\u8f6c\u4e49\uff1a
\\\\ = \u8f6c\u4e49\u540e\u7684 \ (\u53ef\u7528\u5728split\u4e2d) (\u8fd9\u4e2a\u6700\u65e0\u803b)
\\. = \u8f6c\u4e49\u540e\u7684 . (\u53ef\u7528\u5728split\u4e2d)
\\, = \u8f6c\u4e49\u540e\u7684 , (\u53ef\u7528\u5728split\u4e2d)
\\| = \u8f6c\u4e49\u540e\u7684 | (\u53ef\u7528\u5728split\u4e2d)
\\^ = \u8f6c\u4e49\u540e\u7684 ^ (\u53ef\u7528\u5728split\u4e2d)
\\* = \u8f6c\u4e49\u540e\u7684 * (\u53ef\u7528\u5728split\u4e2d)
......................................
String[]
split(String regex)
String s = "123-#-jjj";
String[] s2 = s.split("-#-");
string.split("#")
String str = "123-#-jjj";
String[] resArray = str.split("-#-");
就这么简单
String str = "123-#-jjj";//待分割的字符串
String[] arr = str.split("[-#]");//使用正则表达式进行匹配,多个字符匹配划分
List<String> list = new ArrayList<String>();//存放分割的字符结果
for(String s : arr){
if(StringUtils.isNotEmpty(s)){//或者写成 if(null!=s && !"".equals(s))
list.add(s);//s就是分割后的字符串
}
}
"123-#-jjj".split("-#-");
扩展阅读:java serializable ... java math round ... javascript split ... java poi ... java serversocket ... java replace ... java println ... java split 方法 ... java string format ...