Docs Menu

RealmDictionary - Android SDKicons/link.png

On this page

  • Usage
  • Notifications

New in version 10.6.0.

You can use the RealmDictionary data type to manage a collection of unique String keys paired with values. RealmDictionary implements Java's Map interface, so it works just like the built-in HashMap class, except managed RealmDictionary instances persist their contents to a realm. RealmDictionary instances that contain Realm objects store references to those objects. When you delete a Realm object from a realm, any references to that object in a RealmDictionary become null values.

To create a field of type RealmDictionary, define an object property of type RealmDictionary<T>, where T defines the values you would like to store in your RealmDictionary. Currently, RealmDictionary instances can only use keys of type String.

To subscribe to changes to a RealmDictionary, pass a MapChangeListener implementation to the RealmSet.addChangeListener method. Your MapChangeListener implementation must define an onChange() method, which accepts a reference to the changed RealmDictionary and a set of changes as parameters. You can access the keys added to the dictionary as well as the keys removed from the dictionary through the MapChangeSet parameter.

On this page

Give Feedback
MongoDB logo
© 2021 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.