Q:

I have a model class, using which I save to realm. How do I use `contains()` to see if the object has already been stored

Here's the model class - 
public class BasicSavedInfoImpl extends RealmObject implements BasicSavedInfo {

    private String iD;

    @Override
    public String getID() {
        return iD;
    }

    @Override
    public void setID(String ID) {
        this.iD= ID;
    }

}

Here's how I write id to realm - 
realm.beginTransaction();
        BasicSavedInfoImpl basicSavedInfoImpl = realm.createObject(BasicSavedInfoImpl.class);
        basicSavedInfoImpl.setID(id);
        realm.commitTransaction();

How do I check to see it realm already contains the id?

A:

Any reason you want to use contains? The below would be more precise:
BasicSavedInfoImpl obj = realm.where(BasicSavedInfoImpl.class).equalTo("id", id).findFirst();
if (obj != null) {
  // success
}

If you want to use contains the following should work
RealmResults<BasicSavedInfoImpl> objs = realm.where(BasicSavedInfoImpl.class).contains("id", id).findAll();
if (objs.size() > 0) {
  // success
}

But contains will probably match ID's you don't want, ie. contains("id", "a") would also match ID's "ab", "abc", "ba" and so on.

