{"id":1122,"date":"2022-10-24T22:44:27","date_gmt":"2022-10-24T14:44:27","guid":{"rendered":"https:\/\/qaqaq.top\/?p=1122"},"modified":"2022-11-27T12:39:49","modified_gmt":"2022-11-27T04:39:49","slug":"%e5%b8%b8%e7%94%a8%e7%b1%bb-string%e8%af%be%e5%90%8e%e7%ae%97%e6%b3%95%e9%a2%98%e7%9b%ae3%e3%80%81string%e8%af%be%e5%90%8e%e7%ae%97%e6%b3%95%e9%a2%98%e7%9b%ae3%e6%8b%93%e5%b1%95","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=1122","title":{"rendered":"\u5e38\u7528\u7c7b-String\u8bfe\u540e\u7b97\u6cd5\u9898\u76ee3\u3001String\u8bfe\u540e\u7b97\u6cd5\u9898\u76ee3\u62d3\u5c55"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P477;\r\n\r\nimport org.junit.jupiter.api.Test;\r\n\r\nimport java.util.Arrays;\r\n\r\n\/**\r\n * @author RichieZhang\r\n * @create 2022-10-23 \u4e0b\u5348 3:24\r\n *\/\r\npublic class StringDemo2 {\r\n\r\n    \/*\r\n    \u83b7\u53d6\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e2d\u6700\u5927\u76f8\u540c\u5b50\u4e32\u3002\u6bd4\u5982\uff1a\r\n    str1 = \"abcwerthelloyuiodef\u201c;str2 = \"cvhellobnm\"\r\n    \u63d0\u793a\uff1a\u5c06\u77ed\u7684\u90a3\u4e2a\u4e32\u8fdb\u884c\u957f\u5ea6\u4f9d\u6b21\u9012\u51cf\u7684\u5b50\u4e32\u4e0e\u8f83\u957f\u7684\u4e32\u6bd4\u8f83\u3002\r\n\r\n     *\/\r\n    \/\/\u524d\u63d0\uff1a\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e2d\u53ea\u6709\u4e00\u4e2a\u6700\u5927\u76f8\u540c\u5b57\u4e32\r\n    public String getMaxSameString(String str1, String str2) {\r\n        if (str1 != null &amp;&amp; str2 != null) {\r\n            String maxStr = (str1.length() >= str2.length()) ? str1 : str2;\r\n            String minStr = (str1.length() &lt; str2.length()) ? str1 : str2;\r\n            int length = minStr.length();\r\n            for (int i = 0; i &lt; length; i++) {\r\n\r\n                for (int x = 0, y = length - i; y &lt;= length; x++, y++) {\r\n                    String subStr = minStr.substring(x, y);\r\n                    if (maxStr.contains(subStr)) {\r\n                        return subStr;\r\n                    }\r\n                }\r\n            }\r\n\r\n        }\r\n        return null;\r\n    }\r\n\r\n    \/\/ \u5982\u679c\u5b58\u5728\u591a\u4e2a\u957f\u5ea6\u76f8\u540c\u7684\u6700\u5927\u76f8\u540c\u5b50\u4e32\r\n    \/\/ \u6b64\u65f6\u5148\u8fd4\u56deString&#91;]\uff0c\u540e\u9762\u53ef\u4ee5\u7528\u96c6\u5408\u4e2d\u7684ArrayList\u66ff\u6362\uff0c\u8f83\u65b9\u4fbf\r\n    public String&#91;] getMaxSameString1(String str1, String str2) {\r\n        if (str1 != null &amp;&amp; str2 != null) {\r\n            StringBuffer sBuffer = new StringBuffer();\r\n            String maxString = (str1.length() > str2.length()) ? str1 : str2;\r\n            String minString = (str1.length() > str2.length()) ? str2 : str1;\r\n\r\n            int len = minString.length();\r\n            for (int i = 0; i &lt; len; i++) {\r\n                for (int x = 0, y = len - i; y &lt;= len; x++, y++) {\r\n                    String subString = minString.substring(x, y);\r\n                    if (maxString.contains(subString)) {\r\n                        sBuffer.append(subString + \",\");\r\n                    }\r\n                }\r\n\/\/                System.out.println(sBuffer);\r\n                if (sBuffer.length() != 0) {\r\n                    break;\r\n                }\r\n            }\r\n            String&#91;] split = sBuffer.toString().replaceAll(\",$\", \"\").split(\"\\\\,\");\r\n            return split;\r\n        }\r\n\r\n        return null;\r\n    }\r\n\r\n    @Test\r\n    public void testGetMaxSameString(){\r\n        String str1 = \"abcwerthello1yuiodefabcdef\";\r\n        String str2 = \"cvhello1bnmabcdef\";\r\n        String&#91;] maxSameStrings = getMaxSameString1(str1, str2);\r\n        System.out.println(Arrays.toString(maxSameStrings));\r\n    }\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-1122","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1122"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1122"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1122\/revisions"}],"predecessor-version":[{"id":1123,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1122\/revisions\/1123"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}