java字符串查找

public class Test {

    /**
     * 比较字符串,字符串str中是否包含s字符串
     * 
     * @param str
     * @param s
     * @return
     * 
     * @author kakukyowu
     */
    public static boolean getString(String str, String s) {

        return str.matches(s + ".*");
    }

    /**
     * main函数
     * 
     * @param args
     * 
     * @author kakukyowu
     */
    public static void main(String[] args) {

        String str = "testtesttest5566testtest";

        // 测试一
        String s1 = "556";
        boolean b1 = getString(str, s1);

        // 测试二
        String s2 = "test";
        boolean b2 = getString(str, s2);

        System.out.println("测试一: " + (b1 ? "包含" : "不包含"));
        System.out.println("测试二: " + (b2 ? "包含" : "不包含"));

    }
}


你可能感兴趣的:(java,String,测试,Class)