我想比较 db4o 和 JSON 中的对象。如果 JSON 中不存在该对象,我应该删除 db4o 中的对象。
我对 if 有疑问:
if(tratdb4o.getMedication()==tratJson.getMedication()
我记录了两个字符串变量,两者相同,但没有进入 If 来更改 igual 的值。
有人知道为什么吗?
for (int i=0;it2.hasNext();i++ ) {
objetoDb4o=it2.next();
tratdb4o=(Tratam)objetoDb4o;
for (int j=0;it.hasNext();j++ ) {
objetoJson = it.next();
tratJson = (Tratam)objetoJson;
Log.d(TAG,"Comparing "+tratdb4o.getMedication()+" of db4o "+ tratJson.getMedication() +" of JSON");
if(tratdb4o.getMedication()==tratJson.getMedication()
igual true;
}
if (igual==false){
db4oHelper.db().delete(tratdb4o);
db4oHelper.listResult();
}
igual=false;
it=listaendb4o.iterator();
}
}
最佳答案
而不是
tratdb4o.getMedication()==tratJson.getMedication()
做
tratdb4o.getMedication().equals(tratJson.getMedication())
关于java - 比较两个字段时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12152884/