您的位置:首页 > 其它

怎么判断一个字符串是另一个的子串

2009-07-28 20:09 323 查看
package lmj.zdsoft.efforts.string;

/*
* 判断字符串包含关系 及String一些用法
*
*/

public class xx {

public static boolean getBoo(String str1, String str2) {
boolean b = false;

if (str1.length() > str2.length()) {
int i = str1.indexOf(str2);
if (i > 0) {
return true;
} else {
return b;
}

} else {
int i = str2.indexOf(str1);
if (i > 0) {
return true;
} else {
return b;
//newInstance();
}

}
}

public static void main(String[] avb) {
//法一
String a = "1232456789";
String b = "876";
boolean c = getBoo(a, b);
if (c == true) {
System.out.print("OK");
} else {
System.out.print("NO");
}

//法二
String fatherString = "I love you lmj";

String sonString = "lmj";
if(fatherString.contains(sonString))
System.out.println("the relation is father and son");

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: