我希望我的应用程序以字符串形式读取任何匹配项。我想将匹配变量存储为字符串
Scanner reader = new Scanner(System.in);
System.out.println("Problem 1: Create a heading using h1 tag");
String input = reader.nextLine();
Pattern regex = Pattern.compile("<[a-z][0-9]>");
Matcher m = regex.matcher(input);
if(m.find()){
String meme = m.group(0);
System.out.println(meme);
if(meme == "<h1>"){
System.out.println("Found a string.");
}
else{
System.out.println("No string found.");
}
}
else{
System.out.println("No closing tag.");
}
例如我
输入<..h1..>
(无视点) 但输出总是No string found
即使我设置模因== <..h1..>
。我怎样才能将其转换为字符串?
正是我所需要的!公认。 – Yupyep