Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 671
Salmaan Avatar asked May 15 '15 12:05

Salmaan


People also ask

Can ArrayList hold string?

The Java collection classes, including ArrayList, have one major constraint: they can only store pointers to objects, not primitives. So an ArrayList can store pointers to String objects or Color objects, but an ArrayList cannot store a collection of primitives like int or double.

What is RealmList?

RealmList is used to model one-to-many relationships in a RealmObject . RealmList has two modes: A managed and unmanaged mode. In managed mode all objects are persisted inside a Realm, in unmanaged mode it works as a normal ArrayList. Only Realm can create managed RealmLists.


1 Answers

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.

like image 196
Thomas Goyne Avatar answered Oct 02 '22 16:10

Thomas Goyne