我有点麻烦。问题是当我尝试比较2个字符串(字符串类型)运算符'=='时返回FALSE,但实际上字符串相等。这是带有问题的代码:
//before the following code I filled the "LinkedList <String> command" and there is
//a node with value of args[0]
String deal="";
Iterator it = commands.listIterator();
if(it.hasNext() == true)
{
if(it.next() == args[0])
{
deal += it.next();
it.hasNext();
break;
}
}
谢谢你!!!
要比较两个字符串,您应该使用equals()或equalsIgnoreCase()方法。
在您的情况下:
if(it.next().equals(args[0]))
如果两个对象是相同的对象,并且在内存中具有相同的地址,则operator ==返回true。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句