Search code examples
javaandroidrealm

Clause IN Realm Java


I have been reading Realm Java documentation and I couldn't find something like clause "IN" in SQL, somebody maybe have worked with something similar?. Currently I'm using a loop to bring results one by one, but I don't want to do that.

I would appreciate your help!


Solution

  • Realm has supported the in clause for some time, but wasn't officially documented until 3.1.3. It works for use with Strings, numeric fields, dates and binary data.

    Example Usage with Strings:

    realm.where(Person.class)
         .in("name", new String[]{"Jill", "William", "Trillian"})
         .findAll();
    

    Or optionally you can ignore case..

    realm.where(Person.class)
         .in("name", new String[]{"Jill"}, Case.INSENSITIVE)
         .findAll();
    

    See https://realm.io/docs/java/latest/#filtering for more info.