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
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With