{"id":216960,"date":"2021-05-08T10:43:11","date_gmt":"2021-05-08T02:43:11","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=216960"},"modified":"2021-04-25T09:44:50","modified_gmt":"2021-04-25T01:44:50","slug":"overview-of-how","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/overview-of-how.html","title":{"rendered":"Java StringTokenizer \u7c7b\u4f7f\u7528\u65b9\u6cd5\u6982\u8ff0"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nJava StringTokenizer \u5c5e\u4e8e java.util \u5305\uff0c\u7528\u4e8e\u5206\u9694\u5b57\u7b26\u4e32\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"
\nStringTokenizer \u6784\u9020\u65b9\u6cd5\uff1a<\/strong><\/p>\n

    \n
  1. StringTokenizer(String str) \uff1a\u6784\u9020\u4e00\u4e2a\u7528\u6765\u89e3\u6790 str \u7684 StringTokenizer \u5bf9\u8c61\u3002java \u9ed8\u8ba4\u7684\u5206\u9694\u7b26\u662f\u7a7a\u683c(\"\")\u3001\u5236\u8868\u7b26(\\t)\u3001\u6362\u884c\u7b26(\\n)\u3001\u56de\u8f66\u7b26(\\r)\u3002<\/li>\n
  2. StringTokenizer(String str, String delim) \uff1a\u6784\u9020\u4e00\u4e2a\u7528\u6765\u89e3\u6790 str \u7684 StringTokenizer \u5bf9\u8c61\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e2a\u6307\u5b9a\u7684\u5206\u9694\u7b26\u3002<\/li>\n
  3. StringTokenizer(String str, String delim, boolean returnDelims) \uff1a\u6784\u9020\u4e00\u4e2a\u7528\u6765\u89e3\u6790 str \u7684 StringTokenizer \u5bf9\u8c61\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e2a\u6307\u5b9a\u7684\u5206\u9694\u7b26\uff0c\u540c\u65f6\uff0c\u6307\u5b9a\u662f\u5426\u8fd4\u56de\u5206\u9694\u7b26\u3002<\/li>\n<\/ol>\n

    StringTokenizer \u5e38\u7528\u65b9\u6cd5\uff1a<\/strong><\/p>\n

      \n
    1. nt countTokens()\uff1a\u8fd4\u56denextToken\u65b9\u6cd5\u88ab\u8c03\u7528\u7684\u6b21\u6570\u3002<\/li>\n
    2. boolean hasMoreTokens()\uff1a\u8fd4\u56de\u662f\u5426\u8fd8\u6709\u5206\u9694\u7b26\u3002<\/li>\n
    3. boolean hasMoreElements()\uff1a\u5224\u65ad\u679a\u4e3e \uff08Enumeration\uff09 \u5bf9\u8c61\u4e2d\u662f\u5426\u8fd8\u6709\u6570\u636e\u3002<\/li>\n
    4. String nextToken()\uff1a\u8fd4\u56de\u4ece\u5f53\u524d\u4f4d\u7f6e\u5230\u4e0b\u4e00\u4e2a\u5206\u9694\u7b26\u7684\u5b57\u7b26\u4e32\u3002<\/li>\n
    5. Object nextElement()\uff1a\u8fd4\u56de\u679a\u4e3e \uff08Enumeration\uff09 \u5bf9\u8c61\u7684\u4e0b\u4e00\u4e2a\u5143\u7d20\u3002<\/li>\n
    6. String nextToken(String delim)\uff1a\u4e0e 4 \u7c7b\u4f3c\uff0c\u4ee5\u6307\u5b9a\u7684\u5206\u9694\u7b26\u8fd4\u56de\u7ed3\u679c\u3002<\/li>\n<\/ol>\n

      \u5b9e\u4f8b 1<\/strong><\/p>\n

      import java.util.*;\r\n \r\npublic class Main \r\n{ \r\n    public static void main(String[] args)\r\n    { \r\n        String str = \"runoob,google,taobao,facebook,zhihu\";\r\n        \/\/ \u4ee5 , \u53f7\u4e3a\u5206\u9694\u7b26\u6765\u5206\u9694\u5b57\u7b26\u4e32\r\n        StringTokenizer st=new StringTokenizer(str,\",\");\r\n        while(st.hasMoreTokens()) { \r\n            System.out.println(st.nextToken());\r\n        }\r\n    }\r\n}<\/pre>\n

      \u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n

      runoob\r\ngoogle\r\ntaobao\r\nfacebook\r\nzhihu<\/pre>\n

      \u5b9e\u4f8b 2<\/strong><\/p>\n

      import java.util.*;\r\n \r\npublic class Main\r\n{\r\n    public static void main(String args[])\r\n    {\r\n        System.out.println(\"\u4f7f\u7528\u7b2c\u4e00\u79cd\u6784\u9020\u51fd\u6570\uff1a\");\r\n        StringTokenizer st1 = new StringTokenizer(\"Hello Runoob How are you\", \" \");\r\n        while (st1.hasMoreTokens())\r\n            System.out.println(st1.nextToken());\r\n \r\n        System.out.println(\"\u4f7f\u7528\u7b2c\u4e8c\u79cd\u6784\u9020\u51fd\u6570\uff1a\");\r\n        StringTokenizer st2 = new StringTokenizer(\"JAVA : Code : String\", \" :\");\r\n        while (st2.hasMoreTokens())\r\n            System.out.println(st2.nextToken());\r\n \r\n        System.out.println(\"\u4f7f\u7528\u7b2c\u4e09\u79cd\u6784\u9020\u51fd\u6570\uff1a\");\r\n        StringTokenizer st3 = new StringTokenizer(\"JAVA : Code : String\", \" :\",  true);\r\n        while (st3.hasMoreTokens())\r\n            System.out.println(st3.nextToken());\r\n    }\r\n}<\/pre>\n

      \u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n

      \u4f7f\u7528\u7b2c\u4e00\u79cd\u6784\u9020\u51fd\u6570\uff1a<\/p>\n

      Hello\r\nRunoob\r\nHow\r\nare\r\nyou\r\n\u4f7f\u7528\u7b2c\u4e8c\u79cd\u6784\u9020\u51fd\u6570\uff1a\r\nJAVA\r\nCode\r\nString\r\n\u4f7f\u7528\u7b2c\u4e09\u79cd\u6784\u9020\u51fd\u6570\uff1a\r\nJAVA\r\n \r\n:\r\n \r\nCode\r\n \r\n:\r\n \r\nString<\/pre>\n","protected":false},"excerpt":{"rendered":"

      StringTokenizer \u6784\u9020\u65b9\u6cd5\uff1a StringTokenizer(String str) \uff1a\u6784\u9020\u4e00\u4e2a […]<\/p>\n","protected":false},"author":1470,"featured_media":216962,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-216960","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/216960","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=216960"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/216960\/revisions"}],"predecessor-version":[{"id":216964,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/216960\/revisions\/216964"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/216962"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=216960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=216960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=216960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}