天天看点

java同一个查询不更新数据,如何从领域数据库查询具有不同结果的Java

java同一个查询不更新数据,如何从领域数据库查询具有不同结果的Java

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

uid

AA

AA

BB

CC

DD

BB

BB

I want to get just

AA,

BB,

CC,

DD.

Only one time.

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

Thanks for answers.

解决方案

UPDATED :

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

// Returns the set of users that all have a different name

RealmResults users = realm.where(User.class).distinct("name");

Note:

.distinct will only work on fields that are indexed (@Index or @PrimaryKey).

It doesn't work with child object property.