Realm Android - How can I convert RealmResults to array of objects?

Alexey K picture Alexey K · Mar 5, 2016 · Viewed 25.6k times · Source

I have an object

public class ArticleList extends RealmObject {

@PrimaryKey
private String id;
private String title;
private String subtitle;
private String image;
private String category;

}

What I want to do is to fetch result from Realm and them convert result to ArticleList[]

Fetch I do by using

RealmResults<ArticleList> results = realm.where(ArticleList.class).equalTo("category", "CategoryName").findAll();

What do I have to do next to get an array of objects ?

Answer

Farhan picture Farhan · Sep 9, 2016

Simplest to convert into java ArrayList:

    ArrayList<People> list = new ArrayList(mRealm.where(People.class).findAll());