Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我没有Java经验,我有一个问题。
使用 Jsoup,我有一个名为 td 的元素。如果我做:
String attr = td.attr("class"); System.out.println(attr);
输出是“免费的”,这完全没问题。如果我做:
String attr = td.attr("class"); if (attr == "free") { System.out.println("freedom!"); }
没有输出!
有谁知道如何解决这个问题?
提前致谢。
您必须使用该equals方法作为==比较引用来比较字符串,而不是字符串内容。
equals
==
String attr = td.attr("class"); if (attr.equals("free")) { System.out.println("freedom!"); }