public class Test {
public static void main(String[] args) throws Exception {
String a = "abcsacybhjncfyghbjkl";
String b = "xfghjkkyubjonrdtvb";
System.out.println(hasSameStrBtwStr(a, b, 2));
}
public static boolean hasSameStrBtwStr(String str1,String str2,int contentLength) throws Exception{
boolean result = false;
if(contentLength <=0 || contentLength> str1.length()||contentLength>str2.length()){
throw new Exception("params not legal");
}else{
for(int i = 0;i<str1.length()-contentLength;i++){
String strtmp = str1.substring(i, i+contentLength);
if (str2.contains(strtmp)) {
System.out.println(strtmp);
result = true;
break;
}else{
continue;
}
}
}
return result;
}
}
温馨提示:内容为网友见解,仅供参考