Docs Menu

Class RealmMap

On this page

  • io.realm
  • Method Summary
  • Inherited Methods
  • Method Detail
  • addChangeListener
  • clear
  • containsKey
  • containsValue
  • entrySet
  • freeze
  • get
  • isEmpty
  • isFrozen
  • isManaged
  • isValid
  • keySet
  • put
  • putAll
  • remove
  • removeAllChangeListeners
  • removeChangeListener
  • size
  • values
java.lang.Object
io.realm.RealmMap

Implemented interfaces:

RealmMap is used to map keys to values. A RealmMap cannot contain duplicate keys and each key can map to at most one value. A RealmMap cannot have null keys but can have null values.

Similarly to RealmList s, a RealmDictionary can operate in managed and unmanaged modes. In managed mode a RealmDictionary persists all its contents inside a Realm whereas in unmanaged mode it functions like a HashMap .

Managed RealmDictionaries can only be created by Realm and will automatically update its content whenever the underlying Realm is updated. Managed RealmDictionaries can only be accessed using the getter that points to a RealmDictionary field of a RealmObject .

Unmanaged RealmDictionaries can be created by the user and can contain both managed and unmanaged RealmObjects. This is useful when dealing with JSON deserializers like GSON or other frameworks that inject values into a class. Unmanaged RealmMaps can be added to a Realm using the Realm.copyToRealm(Iterable, ImportFlag...) method.

Modifier and Type
Method and Description
public void
public void

Adds a change listener to this RealmMap .

public void
public boolean
public boolean
public Set
public RealmMap
public V
get (
Object key
)
public boolean
public boolean
public boolean
public boolean
public Set
public V
put (
K key,
V value
)
public void
public V
public void

Removes all user-defined change listeners.

public void

Removes the specified change listener.

public void

Removes the specified change listener.

public int
size ()

public Collection
  • Methods inherited from class java.lang.Object : getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize

Adds a change listener to this RealmMap .

Registering a change listener will not prevent the underlying RealmMap from being garbage collected. If the RealmMap is garbage collected, the change listener will stop being triggered. To avoid this, keep a strong reference for as long as appropriate e.g. in a class variable.

public class MyActivity extends Activity {
private RealmMap<String, Dog> dogs; // Strong reference to keep listeners alive
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dogs = realm.where(Person.class).findFirst().getDogs();
dogs.addChangeListener(new RealmChangeListener<RealmMap<String, Dog>>() {
@Override
public void onChange(RealmMap<String, Dog> map) {
// React to change
}
});
}
}

Parameters

  • listener - the change listener to be notified.

Throws

Tip
See also:

Adds a change listener to this RealmMap .

Registering a change listener will not prevent the underlying RealmMap from being garbage collected. If the RealmMap is garbage collected, the change listener will stop being triggered. To avoid this, keep a strong reference for as long as appropriate e.g. in a class variable.

public class MyActivity extends Activity {
private RealmMap<String, Dog> dogs; // Strong reference to keep listeners alive
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dogs = realm.where(Person.class).findFirst().getDogs();
dogs.addChangeListener(new MapChangeListener<String, Dog>() {
@Override
public void onChange(RealmMap<String, Dog> map, MapChangeSet<String> changeSet) {
// React to change
}
});
}
}

Parameters

  • listener - the change listener to be notified.

Throws

public void clear ()

public boolean containsKey (
Object key
)
public boolean containsValue (
Object value
)
public Set entrySet ()

public RealmMap freeze ()

public V get (
Object key
)
public boolean isEmpty ()

public boolean isFrozen ()

public boolean isManaged ()

public boolean isValid ()

public Set keySet ()

public V put (
K key,
V value
)
public V remove (
Object key
)

Removes all user-defined change listeners.

Throws

Removes the specified change listener.

Parameters

  • listener - the change listener to be removed.

Throws

Removes the specified change listener.

Parameters

  • listener - the change listener to be removed.

Throws

public int size ()

public Collection values ()

←  Class RealmListInterface RealmMigration →
Give Feedback
© 2022 MongoDB, Inc.

About

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