可能重复:
如何比较 Java 中的字符串?
我有这段代码,它在从 url 检索值时工作正常,但它没有认识到字符串是“True”是我需要的 toString() 还是其他什么?
try {
URL url = new URL("http://www.koolflashgames.com/test.php?id=1");
URLConnection yc = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc
.getInputStream()));
inputLine = in.readLine();
inputLine = inputLine.toString();
if(inputLine == "True") {
logger.info(inputLine);
player.sendMessage("Thanks");
}else{
logger.info(inputLine);
player.sendMessage("HAHAHA");
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}