16

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

4

2 回答 2

17

Yes, you have to manually box your strings in a StringObject. We'd like to add support for RealmList<String>, RealmList<Integer>, etc., but it's a long way out.

于 2015-05-15T18:58:00.350 回答
5

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<>();    
于 2018-05-24T07:07:46.147 回答