question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

List<E> to RealmList<E>

See original GitHub issue

Sorry if this is noob question, but I just ran into this issue…

Say I have a bunch of objects in ArrayList<MyObject> list and I want to add it to my other realm object, how do I do that?

class OtherObject extends RealmObject {
    private RealmList<MyObject> list;
    // setter & getter
}

How to add that ArrayList to OtherObject.setList(RealmList<MyObject> list)?

I’ve tried RealmList<MyObject> realmList = (RealmList<MyObject>) realm.copyToRealm(list) but got cast exception.

Thanks.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
emanuelezcommented, Jul 9, 2015

Also this should work and save some memory:

realm.beginTransaction();
OtherObject.getList().addAll(list);
realm.commitTransaction();
9reactions
beeendercommented, Jul 9, 2015

Try this:

realm.beginTransaction();
OtherObject.setList(new RealmList<YouModel>(list.toArray(new YouModel[list.size()])));
realm.commitTransaction();
Read more comments on GitHub >

github_iconTop Results From Across the Web

How convert from List to RealmList<RelmInt>? #5265 - GitHub
My model: public class Company extends RealmObject { @PrimaryKey private long id; private RealmList favorIds; private String address; ...
Read more >
Rx Java parsing a List to RealmList - Stack Overflow
Rx Java parsing a List to RealmList ... Which is fine. however I want to get a RealmList. How can I achieve that?...
Read more >
RealmList (Realm 10.10.1) - MongoDB
Returns true if the list contains the specified element when attached to a Realm. This method will query the native Realm underlying storage...
Read more >
io.realm.RealmList Java Examples - ProgramCreek.com
This page shows Java code examples of io.realm.RealmList.
Read more >
RealmList<RealmString> is an anti-pattern! - Medium
Solution: storing RealmList<primitive> as a String ... Yup, the problem is that people try to store the primitives as a List . It...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found