equals并==返回false文本块字符串,尽管它们在控制台中打印相同的内容。
public class Example {
public static void main(String[] args) {
String jsonLiteral = ""
+ "{\n"
+ "\tgreeting: \"Hello\",\n"
+ "\taudience: \"World\",\n"
+ "\tpunctuation: \"!\"\n"
+ "}\n";
String jsonBlock = """
{
greeting: "Hello",
audience: "World",
punctuation: "!"
}
""";
System.out.println(jsonLiteral.equals(jsonBlock)); //false
System.out.println(jsonBlock == jsonLiteral);
}
}
我缺少什么?
GCT1015
相关分类