E - The class of objects in list.public class RealmList<E extends RealmObject>
extends java.util.AbstractList<E>
RealmObject.
RealmList has two modes: A managed and non-managed mode. In managed mode all objects are persisted
inside a Realm, in non-managed mode it works as a normal ArrayList.
Only Realm can create managed RealmLists. Managed RealmLists will automatically update the
content whenever the underlying Realm is updated, and can only be accessed using the getter
of a RealmObject.
Non-managed RealmLists can be created by the user and can contain both managed and non-managed
RealmObjects. This is useful when dealing with JSON deserializers like GSON or other
frameworks that inject values into a class. Non-managed elements in this list can be added to a
Realm using the Realm.copyToRealm(Iterable) method.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
MANAGED_OBJECTS_NOT_ALLOWED_MESSAGE |
| Constructor and Description |
|---|
RealmList()
Create a RealmList in non-managed mode, where the elements are not controlled by a Realm.
|
RealmList(E... objects)
Create a RealmList in non-managed mode with an initial list of elements.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E object) |
void |
add(int location,
E object) |
void |
clear() |
E |
first()
Find the first object.
|
E |
get(int location) |
E |
last()
Find the last object.
|
void |
move(int oldPos,
int newPos)
Moves an object from one position to another, while maintaining a fixed sized list.
|
E |
remove(int location) |
E |
set(int location,
E object) |
int |
size() |
java.lang.String |
toString() |
RealmQuery<E> |
where()
Returns a RealmQuery, which can be used to query for specific objects of this class
|
addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subListaddAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArrayclone, finalize, getClass, notify, notifyAll, wait, wait, waitpublic static final java.lang.String MANAGED_OBJECTS_NOT_ALLOWED_MESSAGE
public RealmList()
ArrayList and it is not possible
to query the objects in this state.
Use Realm.copyToRealm(Iterable) to properly persist it's elements in
Realm.
public RealmList(E... objects)
ArrayList and it is not
possible to query the objects in this state.
Use Realm.copyToRealm(Iterable) to properly persist all non-managed elements
in Realm.objects - Initial objects in the list.public void add(int location,
E object)
add in interface java.util.List<E extends RealmObject>add in class java.util.AbstractList<E extends RealmObject>public boolean add(E object)
add in interface java.util.Collection<E extends RealmObject>add in interface java.util.List<E extends RealmObject>add in class java.util.AbstractList<E extends RealmObject>public E set(int location, E object)
set in interface java.util.List<E extends RealmObject>set in class java.util.AbstractList<E extends RealmObject>public void move(int oldPos,
int newPos)
oldPos - Index of RealmObject to move.newPos - Target position. If newPos < oldPos the object at the location will be shifted
to the right. If oldPos < newPos, indexes > oldPos will be shifted once to the
left.java.lang.IndexOutOfBoundsException - if any position is outside [0, size()[.public void clear()
clear in interface java.util.Collection<E extends RealmObject>clear in interface java.util.List<E extends RealmObject>clear in class java.util.AbstractList<E extends RealmObject>public E remove(int location)
remove in interface java.util.List<E extends RealmObject>remove in class java.util.AbstractList<E extends RealmObject>public E get(int location)
get in interface java.util.List<E extends RealmObject>get in class java.util.AbstractList<E extends RealmObject>public E first()
null if the list is empty.public E last()
null if the list is empty.public int size()
size in interface java.util.Collection<E extends RealmObject>size in interface java.util.List<E extends RealmObject>size in class java.util.AbstractCollection<E extends RealmObject>public RealmQuery<E> where()
RealmQuerypublic java.lang.String toString()
toString in class java.util.AbstractCollection<E extends RealmObject>