62,615
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
String str = "I11I4I31I3I5I3";
String regex = "I(?=[1|3]{1})";
Pattern pat= Pattern.compile(regex);
Matcher mat = pat.matcher(str);
if(mat.find()){
System.out.println(" It contant");
}else{
System.out.println("It dose not contant");
}
}
public static void main(String[] args) {
System.out.println(charContains("I1I2I3", "I1I3"));
}
public static boolean charContains(String s, String sub) {
if (s == null || sub == null)
return false;
for (int i = 0; i < sub.length(); i++) {
boolean contains = false;
char c = sub.charAt(i);
for (int j = 0; j < s.length(); j++) {
if (c == s.charAt(j)) {
contains = true;
break;
}
}
if (!contains)
return false;
}
return true;
}