由于某些原因,我的==运算符在它应该返回时不会返回true。我看到两个完全相同的字符串显示在我的手机上,但它仍然没有注册为真实。有任何想法吗?它是pair(string,int)的哈希集合。 getFirst返回该对中的字符串。试图从一组中检测一个字符串
private boolean contains(HashSet<Pair> mySet, String current) {
Iterator<Pair> temp = mySet.iterator();
String compared;
Toast.makeText(MainActivity.this, " want " +current,
Toast.LENGTH_LONG).show();
while (temp.hasNext()) {
compared = temp.next().getFirst();
Toast.makeText(MainActivity.this, compared+" "+current,
Toast.LENGTH_SHORT).show();
if (compared==current)
Toast.makeText(MainActivity.this, "found", Toast.LENGTH_SHORT).show();
}
return false;
}
这个问题已经回答了很多次,现在它甚至不好笑 – Woot4Moo 2012-07-17 00:23:29
这是一个有点搞笑,悲伤的方式。 – dmon 2012-07-17 00:30:50