如何从领域数据库中查询具有不同结果的Java [英] how to query from realm database with distinct results java

查看:75
本文介绍了如何从领域数据库中查询具有不同结果的Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Realm对象类,并在其中存储了大量数据,想象一下我有一个String uid;字段.我想获取uid名称,但是在相同的uid名称上只有一次, 例如

I have got a Realm object class, and storing lots of data in there, imagine that I have a String uid; field. I want to get uid names, but on same uid names just only one time, For example

AA

AA

BB

CC

DD

BB

BB

我想得到 AA,

BB,

CC,

DD.

只有一次. 我查看了领域文档,但找不到任何东西.

Only one time. I looked over realm documentation but couldn't find anything.

感谢答案.

推荐答案

更新时间:

您可以使用distinct()来获取对象类的不同条目.

You can use distinct() to get distinct entries for an object class.

// Returns the set of users that all have a different name
RealmResults<User> users = realm.where(User.class).distinct("name");

注意: .distinct仅适用于已建立索引的字段(@Index或@PrimaryKey). 不适用于子对象属性.

Note: .distinct will only work on fields that are indexed (@Index or @PrimaryKey). It doesn't work with child object property.

您可以在官方文档中找到有关此方法的更多信息. https ://realm.io/docs/java/latest/api/io/realm/Realm.html#distinct-java.lang.Class-java.lang.String-] [1]

You can find more information about this method here in the official documentation. https://realm.io/docs/java/latest/api/io/realm/Realm.html#distinct-java.lang.Class-java.lang.String-][1]

这篇关于如何从领域数据库中查询具有不同结果的Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆