java - 比较两个字段时出错

标签 java android json db4o

我想比较 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/

相关文章:

json - 如何使用 JMESPath 获取键值对并将它们转换为对象数组

javascript - JSON.parse 结果为正确的对象数组

java - 为什么包资源管理器中的源文件夹不按字母顺序显示

android - 无法访问 com.google.android.gms.internal.zzbfm 的 zzbfm 类文件未找到

android - 移轴图像处理效果

android - 如何绘制衰落路径

json - 公共(public)相册突然需要access_token

java - 这是一个虚假的唤醒还是只是一个时髦的(非虚假的)竞争条件?

java - 何时在 Cassandra 中使用 UUID 而不是毫秒时间戳?

java - 测试类的序列化