1.
public static void main(String args[]) { String[] arr={"12345678","12342311987","abababab"}; for(String str:arr){ boolean flag=false; String matcherStr=""; for(int i=0;i<str.length();i++){ for(int j=i+1;j<str.length();j++){ String temp=str.substring(i,j); temp=temp+temp; Matcher m=Pattern.compile(temp).matcher(str); if(m.find()){ matcherStr=temp; flag=true; break; } } } if(flag){ System.out.println(str+":check->false,multiplicity string:"+matcherStr); }else{ System.out.println(str+":check->true"); flag=false; } } }
2.
if(str.matches("^.*?(.+?)\\1.*?$")){ System.out.println("有重复"); }
时间: 2024-10-06 00:31:00