求两个字符串中的最大相同子串 SubString
原创
©著作权归作者所有:来自51CTO博客作者jdsjlzx的原创作品,请联系作者获取转载授权,否则将追究法律责任
package com.itcast.base;
public class SubStringTest {
public static void main(String[] args) {
String str1 = "ashfjeudccckfjgiccccccjgurhd";
String str2 = "dhfurjcccckgoymjdhccfi";
String max = "";
for (int i = 0; i < str2.length(); i++) {
String temp1 = str2.substring(i);
// System.out.println("temp1:" + temp1);
for (int j = temp1.length() - 1; j >= 0; j--) {
String temp2 = temp1.substring(0, j);
// System.out.println("temp2:" + temp2);
if (str1.indexOf(temp2) != -1 && temp2.length() > max.length()) {
max = temp2;
}
}
}
System.out.println("max:" + max);
}
}