如何验证一个字符串中的每一个字符均在另一个字符串中出现过

package task1;

public class Task14 {
//14.如何验证一个字符串中的每一个字符均在另一个字符串中出现过
	public static void main(String[] args) {
		String string1 = "笑 一 笑十年少";
		String string2 = "笑";
		int total = 0;
		for (String tmp = string1; tmp != null && tmp.length() > string2.length();) {
			if (tmp.indexOf(string2) == 0) {
				total++;
			}
			tmp = tmp.substring(1);
		}
		System.out.println(string1 + "中含有" + total + "个" + string2);

	}

}

console:
笑 一 笑十年少中含有2个笑

你可能感兴趣的:(如何验证一个字符串中的每一个字符均在另一个字符串中出现过)