2017-04-17 1 views

답변

0

기억하십시오! Realm은 NoSQL 객체 저장소입니다! 이것은 가볍고 빠르며 객체가 저장하는 객체는 단지 Java 객체입니다. DB 엔진이 이와 같은 계산을 "최적화"할 필요가 없습니다. 다음과 같이 쉽게 할 수 있습니다.

public String getMostCommonName(Realm realm) { 
    RealmResults<Person> results = realm.where(Person.class).distinct("name"); 
    long maxOccurances = 0; 
    Person mostCommon = null; 
    for (Person p : results) { 
     long n = realm.where(Person.class).equalTo("name", p.getName()).count(); 
     if (n > maxOccurances) { 
      mostCommon = p; 
      maxOccurances = n; 
     } 
    } 
    return mostCommon.getName(); 
} 
관련 문제