用正则表达式匹配字符串
/* 来自 时代Java - N o w J a v a . c o m*/ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private String jaText = "this is a test "; public Main() { Pattern p = Pattern.compile(".at"); Matcher m = p.matcher(jaText); while (m.find()) { System.out.printf("%s\n", m.group()); } } }