您的位置:首页 > 编程语言 > Java开发

Java中matches()方法声明

2015-11-20 23:12 399 查看
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 falseSystem.out.println("Value returned = " + retval);retval = str2.matches("learning");// method gets same values therefore it returns trueSystem.out.println("Value returned = " + retval);retval = str1.matches("tuts");// method gets different values therefore it returns falseSystem.out.println("Value returned = " + retval);}}
结果为:
Value returned = falseValue returned = trueValue returned = false
另外,这个也挺好!点击打开链接<天才搬运工>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: