matches() 方法告诉这个字符串是否匹配给定的正则表达式
声明
public boolean matches(String regex)、
import java.lang.*;
public class StringDemo {
public static void main(String[] args) {
String str1 = "tutorials", str2 = "learning";
boolean retval = str1.matches(str2);
// method gets different values therefore it returns false
System.out.println("Value returned = " + retval);
retval = str2.matches("learning");
// method gets same values therefore it returns true
System.out.println("Value returned = " + retval);
retval = str1.matches("tuts");
// method gets different values therefore it returns false
System.out.println("Value returned = " + retval);
}
}
结果为:
Value returned = false
Value returned = true
Value returned = false
另外,这个也挺好!
点击打开链接<天才搬运工>