Search code examples
javaandroidjsondb4o

Error comparing two fields


I want to compare objects from db4o and JSON.I should delete the object in db4o if this doesn't exist in JSON.

I've a problem with the if:

if(tratdb4o.getMedication()==tratJson.getMedication()

I Log the two String variables and both are identical but doesn't enter into the If for change the value of igual.

Somebody knows why?

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();
    }
}

Solution

  • instead of

    tratdb4o.getMedication()==tratJson.getMedication()
    

    do

    tratdb4o.getMedication().equals(tratJson.getMedication())