Fetch a single column from Realm Database (Android)

丶灬走出姿态 提交于 2019-12-04 16:48:40

If we using Realm in Android, then which method do we have to use for fetching the data of only one column?

You can't, because Realm is an object store, it doesn't have concept of "columns".


My problem:

results.size() > 10k. So I want to avoid 10k iteration

for(i = 0; i < results.size(); i++){ 
}

Solution: don't iterate?

 RealmResults<User> results = query.findAll();
 //List<String> name = new ArrayList<>(); 
 //for(i = 0; i < results.size(); i++){ 
 //     name.add(result.get(i).getName();
 //}
 return results;

 // ...
 String name = results.get(position).getName();

Look at queries section at the documentation:

All fetches (including queries) are lazy in Realm, and the data is never copied.

This mean, that data of particular column (property) will be fetched when you call getMyProperty() method. Not after call of finadAll() method of RealmQuery object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!