Search code examples
javaandroidarraylistrealmrealm-list

Can I have arrayList of string in realm object android


As we dont have any list data type in realm, how can we use ArrayList<String> in a realm object?
I had same question for the arrayLists of the custom models we make i.e. ArrayList<CustomModel> but for that I understand that we first have to make RealmObject of same Custom model using

public class CustomObject extends RealmObject {
    private String name;
    private String age;
}

and then I can use

private RealmList<CustomObject> customObjectList; 

in another RealmObject

Do i have to do same with arrayList of string?
1. Making String object
2. Use that object in Realm List


Solution

  • Now it is possible to work with RealmList where T can be the following types: String, Integer, Boolean, Float, Double, Short, Long, Byte, byte[] and Date` (according to the official docs https://realm.io/docs/java/latest/#relationships, see Relationships -> List of Primitives)

    For example:

    public RealmList<String> telephoneNumbers = new RealmList<>();