Docs Menu

Class RealmQuery

On this page

java.lang.Object
io.realm.RealmQuery

A RealmQuery encapsulates a query on a io.realm.Realm or a io.realm.RealmResults using the Builder pattern. The query is executed using either findAll() or findFirst() .

The input to many of the query functions take a field name as String. Note that this is not type safe. If a RealmObject class is refactored care has to be taken to not break any queries.

A io.realm.Realm is unordered, which means that there is no guarantee that querying a Realm will return the objects in the order they where inserted. Use sort(String) (String)} and similar methods if a specific order is required.

A RealmQuery cannot be passed between different threads.

Results are obtained quickly most of the times. However, launching heavy queries from the UI thread may result in a drop of frames or even ANRs. If you want to prevent these behaviors, you can instantiate a Realm using a RealmConfiguration that explicitly sets RealmConfiguration.Builder.allowQueriesOnUiThread(boolean) to false . This way queries will be forced to be launched from a non-UI thread. Alternatively, you can also use findAllAsync() or findFirstAsync() .

Tip
See also:
Modifier and Type
Method and Description
public RealmQuery

This predicate will never match, resulting in the query always returning 0 results.

public RealmQuery

This predicate will always match.

public RealmQuery
and ()

Logical-and two conditions Realm automatically applies logical-and between all query statements, so this is intended only as a mean to increase readability.

public double
String fieldName
)

Returns the average of a given field.

public Decimal128

Returns the average of a given field.

public RealmQuery

Begin grouping of conditions ("left parenthesis").

public RealmQuery
String fieldName,
String value,
Case casing
)

Condition that the value of field begins with the specified substring.

public RealmQuery
String fieldName,
String value
)

Condition that the value of field begins with the specified string.

public RealmQuery
String fieldName,
Decimal128 from,
Decimal128 to
)

Between condition.

public RealmQuery
String fieldName,
Date from,
Date to
)

Between condition.

public RealmQuery
String fieldName,
float from,
float to
)

Between condition.

public RealmQuery
String fieldName,
double from,
double to
)

Between condition.

public RealmQuery
String fieldName,
long from,
long to
)

Between condition.

public RealmQuery
String fieldName,
int from,
int to
)

Between condition.

public RealmQuery
String fieldName,
String value,
Case casing
)

Condition that value of field contains the specified substring.

public RealmQuery
String fieldName,
String value
)

Condition that value of field contains the specified substring.

public long

Counts the number of objects that fulfill the query conditions.

public RealmQuery
String firstFieldName,
java.lang.String[] remainingFieldNames
)

Selects a distinct set of objects of a specific class.

public RealmQuery
String fieldName
)

Selects a distinct set of objects of a specific class.

public RealmQuery

End grouping of conditions ("right parenthesis") which was opened by a call to beginGroup() .

public RealmQuery
String fieldName,
String value,
Case casing
)

Condition that the value of field ends with the specified substring.

public RealmQuery
String fieldName,
String value
)

Condition that the value of field ends with the specified string.

public RealmQuery
String fieldName,
ObjectId value
)

Equal-to comparison.

public RealmQuery
String fieldName,
Decimal128 value
)

Equal-to comparison.

public RealmQuery
String fieldName,
String value,
Case casing
)

Equal-to comparison.

public RealmQuery
String fieldName,
String value
)

Equal-to comparison.

Finds all objects that fulfill the query conditions.

Finds all objects that fulfill the query conditions.

public E

Finds the first object that fulfills the query conditions.

public E

Similar to findFirst() but runs asynchronously on a worker thread.

public String

Returns a textual description of this query.

public Realm

Returns the Realm instance to which this query belongs.

public String

Returns the internal Realm name of the type being queried.

public RealmQuery
String fieldName,
ObjectId value
)

Greater-than comparison.

public RealmQuery
String fieldName,
Decimal128 value
)

Greater-than comparison.

public RealmQuery
String fieldName,
Date value
)

Greater-than comparison.

public RealmQuery
String fieldName,
float value
)

Greater-than comparison.

public RealmQuery
String fieldName,
double value
)

Greater-than comparison.

public RealmQuery
String fieldName,
long value
)

Greater-than comparison.

public RealmQuery
String fieldName,
int value
)

Greater-than comparison.

public RealmQuery
String fieldName,
ObjectId value
)

Greater-than-or-equal-to comparison.

public RealmQuery
String fieldName,
Decimal128 value
)

Greater-than-or-equal-to comparison.

public RealmQuery
String fieldName,
Date value
)

Greater-than-or-equal-to comparison.

public RealmQuery
String fieldName,
float value
)

Greater-than-or-equal-to comparison.

public RealmQuery
String fieldName,
double value
)

Greater-than-or-equal-to comparison.

public RealmQuery
String fieldName,
long value
)

Greater-than-or-equal-to comparison.

public RealmQuery
String fieldName,
int value
)

Greater-than-or-equal-to comparison.

public RealmQuery
in (
String fieldName,
)

In comparison.

public RealmQuery
in (
String fieldName,
)

In comparison.

public RealmQuery
in (
String fieldName,
)

In comparison.

public RealmQuery
in (
String fieldName,
)

In comparison.

public RealmQuery
in (
String fieldName,
)

In comparison.

public RealmQuery
in (
String fieldName,
)

In comparison.

public RealmQuery
in (
String fieldName,
)

In comparison.

public RealmQuery
in (
String fieldName,
)

In comparison.

public RealmQuery
in (
String fieldName,
Case casing
)

In comparison.

public RealmQuery
in (
String fieldName,
)

In comparison.

public RealmQuery
String fieldName
)

Condition that finds values that are considered "empty" i.e., an empty list, the 0-length string or byte array.

public RealmQuery
String fieldName
)

Condition that finds values that are considered "Not-empty" i.e., a list, a string or a byte array with not-empty values.

public RealmQuery
String fieldName
)

Tests if a field is not null .

public RealmQuery
String fieldName
)

Tests if a field is null .

public boolean

Checks if io.realm.RealmQuery is still valid to use i.e., the io.realm.Realm instance hasn't been closed and any parent io.realm.RealmResults is still valid.

public RealmQuery
String fieldName,
ObjectId value
)

Less-than comparison.

public RealmQuery
String fieldName,
Decimal128 value
)

Less-than comparison.

public RealmQuery
String fieldName,
long value
)

Less-than comparison.

public RealmQuery
String fieldName,
int value
)

Less-than comparison.

public RealmQuery
String fieldName,
ObjectId value
)

Less-than-or-equal-to comparison.

public RealmQuery
String fieldName,
Decimal128 value
)

Less-than-or-equal-to comparison.

public RealmQuery
String fieldName,
long value
)

Less-than-or-equal-to comparison.

public RealmQuery
String fieldName,
int value
)

Less-than-or-equal-to comparison.

public RealmQuery
String fieldName,
String value,
Case casing
)

Condition that the value of field matches with the specified substring, with wildcards:

  • '*' matches [0, n] unicode chars
  • '?' matches a single unicode char.
public RealmQuery
String fieldName,
String value
)

Condition that the value of field matches with the specified substring, with wildcards:

  • '*' matches [0, n] unicode chars
  • '?' matches a single unicode char.
public RealmQuery
long limit
)

Limits the number of objects returned in case the query matched more objects.

public Number
max (
String fieldName
)

Finds the maximum value of a field.

public Date
String fieldName
)

Finds the maximum value of a field.

public Number
min (
String fieldName
)

Finds the minimum value of a field.

public Date
String fieldName
)

Finds the minimum value of a field.

public RealmQuery
not ()

Negate condition.

public RealmQuery
String fieldName,
ObjectId value
)

Not-equal-to comparison.

public RealmQuery
String fieldName,
Decimal128 value
)

Not-equal-to comparison.

public RealmQuery
String fieldName,
String value,
Case casing
)

Not-equal-to comparison.

public RealmQuery
String fieldName,
String value
)

Not-equal-to comparison.

public RealmQuery
or ()

Logical-or two conditions.

public RealmQuery
java.lang.String[] fieldNames,
io.realm.Sort[] sortOrders
)

Sorts the query result by the specific field names in the provided orders.

public RealmQuery
String fieldName1,
Sort sortOrder1,
String fieldName2,
Sort sortOrder2
)

Sorts the query result by the specific field names in the provided orders.

public RealmQuery
String fieldName,
Sort sortOrder
)

Sorts the query result by the specified field name and order.

public RealmQuery
String fieldName
)

Sorts the query result by the specific field name in ascending order.

public Number
sum (
String fieldName
)

Calculates the sum of a given field.

  • Methods inherited from class java.lang.Object : getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize
This predicate will never match, resulting in the query always returning 0 results.
This predicate will always match.
public RealmQuery and ()

Logical-and two conditions Realm automatically applies logical-and between all query statements, so this is intended only as a mean to increase readability.

Returns

the query object

public double average (
String fieldName
)

Returns the average of a given field. Does not support dotted field notation.

Parameters

  • fieldName - the field to calculate average on. Only number fields are supported.

Returns

the average for the given field amongst objects in query results. This will be of type double for all types of number fields. If no objects exist or they all have null as the value for the given field, 0 will be returned. When computing the average, objects with null values are ignored.

Throws

public Decimal128 averageDecimal128 (
String fieldName
)

Returns the average of a given field. Does not support dotted field notation.

Parameters

  • fieldName - the field to calculate average on. Only Decimal128 fields is supported. For other number types consider using average(String) .

Returns

the average for the given field amongst objects in query results. This will be of type Decimal128. If no objects exist or they all have null as the value for the given field 0 will be returned. When computing the average, objects with null values are ignored.

Throws

Begin grouping of conditions ("left parenthesis"). A group must be closed with a call to endGroup() .

Returns

the query object.

Tip
See also:
String fieldName,
String value,
Case casing
)

Condition that the value of field begins with the specified substring.

Parameters

  • fieldName - the field to compare.
  • value - the substring.
  • casing - how to handle casing. Setting this to Case.INSENSITIVE only works for Latin-1 characters.

Returns

the query object

Throws

String fieldName,
String value
)

Condition that the value of field begins with the specified string.

Parameters

  • fieldName - the field to compare.
  • value - the string.

Returns

the query object.

Throws

String fieldName,
Decimal128 from,
Decimal128 to
)

Between condition.

Parameters

  • fieldName - the field to compare.
  • from - lowest value (inclusive).
  • to - highest value (inclusive).

Returns

the query object.

Throws

String fieldName,
Date from,
Date to
)

Between condition.

Parameters

  • fieldName - the field to compare.
  • from - lowest value (inclusive).
  • to - highest value (inclusive).

Returns

the query object.

Throws

String fieldName,
float from,
float to
)

Between condition.

Parameters

  • fieldName - the field to compare.
  • from - lowest value (inclusive).
  • to - highest value (inclusive).

Returns

the query object.

Throws

String fieldName,
double from,
double to
)

Between condition.

Parameters

  • fieldName - the field to compare.
  • from - lowest value (inclusive).
  • to - highest value (inclusive).

Returns

the query object.

Throws

String fieldName,
long from,
long to
)

Between condition.

Parameters

  • fieldName - the field to compare.
  • from - lowest value (inclusive).
  • to - highest value (inclusive).

Returns

the query object.

Throws

String fieldName,
int from,
int to
)

Between condition.

Parameters

  • fieldName - the field to compare.
  • from - lowest value (inclusive).
  • to - highest value (inclusive).

Returns

the query object.

Throws

String fieldName,
String value,
Case casing
)

Condition that value of field contains the specified substring.

Parameters

  • fieldName - the field to compare.
  • value - the substring.
  • casing - how to handle casing. Setting this to Case.INSENSITIVE only works for Latin-1 characters.

Returns

The query object.

Throws

String fieldName,
String value
)

Condition that value of field contains the specified substring.

Parameters

  • fieldName - the field to compare.
  • value - the substring.

Returns

the query object.

Throws

public long count ()

Counts the number of objects that fulfill the query conditions.

Returns

the number of matching objects.

Throws

String firstFieldName,
java.lang.String[] remainingFieldNames
)

Selects a distinct set of objects of a specific class. When multiple distinct fields are given, all unique combinations of values in the fields will be returned. In case of multiple matches, it is undefined which object is returned. Unless the result is sorted, then the first object will be returned.

Parameters

  • firstFieldName - first field name to use when finding distinct objects.
  • remainingFieldNames - remaining field names when determining all unique combinations of field values.

Throws

String fieldName
)

Selects a distinct set of objects of a specific class. If the result is sorted, the first object will be returned in case of multiple occurrences, otherwise it is undefined which object is returned.Adding io.realm.annotations.Index to the corresponding field will make this operation much faster.

Parameters

  • fieldName - the field name.

Throws

End grouping of conditions ("right parenthesis") which was opened by a call to beginGroup() .

Returns

the query object.

Tip
See also:
String fieldName,
String value,
Case casing
)

Condition that the value of field ends with the specified substring.

Parameters

  • fieldName - the field to compare.
  • value - the substring.
  • casing - how to handle casing. Setting this to Case.INSENSITIVE only works for Latin-1 characters.

Returns

the query object.

Throws

String fieldName,
String value
)

Condition that the value of field ends with the specified string.

Parameters

  • fieldName - the field to compare.
  • value - the string.

Returns

the query object.

Throws

String fieldName,
ObjectId value
)

Equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
Decimal128 value
)

Equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
String value,
Case casing
)

Equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.
  • casing - how to handle casing. Setting this to Case.INSENSITIVE only works for Latin-1 characters.

Returns

the query object.

Throws

String fieldName,
String value
)

Equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

Finds all objects that fulfill the query conditions.Launching heavy queries from the UI thread may result in a drop of frames or even ANRs. We do not recommend doing so and therefore it is not allowed by default. If you want to prevent these behaviors you can obtain a Realm using a RealmConfiguration that explicitly sets RealmConfiguration.Builder.allowQueriesOnUiThread(boolean) to false . This way you will be forced to launch your queries from a non-UI thread, otherwise calls to this method will throw a RealmException . Alternatively, you can use findAllAsync() .

Returns

a io.realm.RealmResults containing objects. If no objects match the condition, a list with zero objects is returned.

Throws

Finds all objects that fulfill the query conditions. This method is only available from a Looper thread.

Returns

immediately an empty RealmResults . Users need to register a listener io.realm.RealmResults.addChangeListener(RealmChangeListener) to be notified when the query completes.

public E findFirst ()

Finds the first object that fulfills the query conditions.Launching heavy queries from the UI thread may result in a drop of frames or even ANRs. We do not recommend doing so, but it is allowed by default. If you want to prevent these behaviors you can obtain a Realm using a RealmConfiguration that explicitly sets RealmConfiguration.Builder.allowQueriesOnUiThread(boolean) to false . This way you will be forced to launch your queries from a non-UI thread, otherwise calls to this method will throw a RealmException . Alternatively, you can use findFirstAsync() .

Returns

the object found or null if no object matches the query conditions.

Throws

public E findFirstAsync ()

Similar to findFirst() but runs asynchronously on a worker thread. An listener should be registered to the returned RealmObject to get the notification when query completes. The registered listener will also be triggered if there are changes made to the queried RealmObject . If the RealmObject is deleted, the listener will be called one last time and then stop. The query will not be re-run.

Returns

immediately an empty RealmObject with isLoaded() == false . Trying to access any field on the returned object before it is loaded will throw an IllegalStateException .

Throws

Returns a textual description of this query.

Returns

the textual description of the query.

public Realm getRealm ()

Returns the Realm instance to which this query belongs.

Calling Realm.close() on the returned instance is discouraged as it is the same as calling it on the original Realm instance which may cause the Realm to fully close invalidating the query.

Returns

Realm instance this query belongs to.

Throws

Returns the internal Realm name of the type being queried.

Returns

the internal name of the Realm model class being queried.

String fieldName,
ObjectId value
)

Greater-than comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
Decimal128 value
)

Greater-than comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
Date value
)

Greater-than comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
float value
)

Greater-than comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
double value
)

Greater-than comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
long value
)

Greater-than comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
int value
)

Greater-than comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
ObjectId value
)

Greater-than-or-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
Decimal128 value
)

Greater-than-or-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
Date value
)

Greater-than-or-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
float value
)

Greater-than-or-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
double value
)

Greater-than-or-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
long value
)

Greater-than-or-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
int value
)

Greater-than-or-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

public RealmQuery in (
String fieldName,
)

In comparison. This allows you to test if objects match any value in an array of values.

Parameters

  • fieldName - the field to compare.
  • values - array of values to compare with. If null or the empty array is provided the query will never match any results.

Returns

the query object.

Throws

public RealmQuery in (
String fieldName,
)

In comparison. This allows you to test if objects match any value in an array of values.

Parameters

  • fieldName - the field to compare.
  • values - array of values to compare with. If null or the empty array is provided the query will never match any results.

Returns

the query object.

Throws

public RealmQuery in (
String fieldName,
)

In comparison. This allows you to test if objects match any value in an array of values.

Parameters

  • fieldName - the field to compare.
  • values - array of values to compare with. If null or the empty array is provided the query will never match any results.

Returns

the query object.

Throws

public RealmQuery in (
String fieldName,
)

In comparison. This allows you to test if objects match any value in an array of values.

Parameters

  • fieldName - the field to compare.
  • values - array of values to compare with. If null or the empty array is provided the query will never match any results.

Returns

the query object.

Throws

public RealmQuery in (
String fieldName,
)

In comparison. This allows you to test if objects match any value in an array of values.

Parameters

  • fieldName - the field to compare.
  • values - array of values to compare with. If null or the empty array is provided the query will never match any results.

Returns

the query object.

Throws

public RealmQuery in (
String fieldName,
)

In comparison. This allows you to test if objects match any value in an array of values.

Parameters

  • fieldName - the field to compare.
  • values - array of values to compare with. If null or the empty array is provided the query will never match any results.

Returns

the query object.

Throws

public RealmQuery in (
String fieldName,
)

In comparison. This allows you to test if objects match any value in an array of values.

Parameters

  • fieldName - the field to compare.
  • values - array of values to compare with. If null or the empty array is provided the query will never match any results.

Returns

the query object.

Throws

public RealmQuery in (
String fieldName,
)

In comparison. This allows you to test if objects match any value in an array of values.

Parameters

  • fieldName - the field to compare.
  • values - array of values to compare with. If null or the empty array is provided the query will never match any results.

Returns

the query object.

Throws

public RealmQuery in (
String fieldName,
Case casing
)

In comparison. This allows you to test if objects match any value in an array of values.

Parameters

  • fieldName - the field to compare.
  • values - array of values to compare with. If null or the empty array is provided the query will never match any results.
  • casing - how casing is handled. Case.INSENSITIVE works only for the Latin-1 characters.

Returns

the query object.

Throws

public RealmQuery in (
String fieldName,
)

In comparison. This allows you to test if objects match any value in an array of values.

Parameters

  • fieldName - the field to compare.
  • values - array of values to compare with. If null or the empty array is provided the query will never match any results.

Returns

the query object.

Throws

String fieldName
)

Condition that finds values that are considered "empty" i.e., an empty list, the 0-length string or byte array.

Parameters

  • fieldName - the field to compare.

Returns

the query object.

Throws

String fieldName
)

Condition that finds values that are considered "Not-empty" i.e., a list, a string or a byte array with not-empty values.

Parameters

  • fieldName - the field to compare.

Returns

the query object.

Throws

String fieldName
)

Tests if a field is not null . Only works for nullable fields.

Parameters

  • fieldName - the field name.

Returns

the query object.

Throws

String fieldName
)

Tests if a field is null . Only works for nullable fields.

For link queries, if any part of the link path is null the whole path is considered to be null e.g., isNull("linkField.stringField") will be considered to be null if either linkField or linkField.stringField is null .

Parameters

  • fieldName - the field name.

Returns

the query object.

Throws

public boolean isValid ()

Checks if io.realm.RealmQuery is still valid to use i.e., the io.realm.Realm instance hasn't been closed and any parent io.realm.RealmResults is still valid.

Returns

true if still valid to use, false otherwise.

String fieldName,
ObjectId value
)

Less-than comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
Decimal128 value
)

Less-than comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
long value
)

Less-than comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
int value
)

Less-than comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
ObjectId value
)

Less-than-or-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
Decimal128 value
)

Less-than-or-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
long value
)

Less-than-or-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
int value
)

Less-than-or-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

public RealmQuery like (
String fieldName,
String value,
Case casing
)

Condition that the value of field matches with the specified substring, with wildcards:

  • '*' matches [0, n] unicode chars
  • '?' matches a single unicode char.

Parameters

  • fieldName - the field to compare.
  • value - the wildcard string.
  • casing - how to handle casing. Setting this to Case.INSENSITIVE only works for Latin-1 characters.

Returns

the query object.

Throws

public RealmQuery like (
String fieldName,
String value
)

Condition that the value of field matches with the specified substring, with wildcards:

  • '*' matches [0, n] unicode chars
  • '?' matches a single unicode char.

Parameters

  • fieldName - the field to compare.
  • value - the wildcard string.

Returns

the query object.

Throws

public RealmQuery limit (
long limit
)

Limits the number of objects returned in case the query matched more objects.Note that when using this method in combination with sort(String) and distinct(String) they will be executed in the order they where added which can affect the end result.

Parameters

  • limit - a limit that is ≥ 1 .

Throws

public Number max (
String fieldName
)

Finds the maximum value of a field.

Parameters

  • fieldName - the field to look for a maximum on. Only number fields are supported.

Returns

if no objects exist or they all have null as the value for the given field, null will be returned. Otherwise the maximum value is returned. When determining the maximum value, objects with null values are ignored.

Throws

public Date maximumDate (
String fieldName
)

Finds the maximum value of a field.

Parameters

  • fieldName - the field name.

Returns

if no objects exist or they all have null as the value for the given date field, null will be returned. Otherwise the maximum date is returned. When determining the maximum date, objects with null values are ignored.

Throws

public Number min (
String fieldName
)

Finds the minimum value of a field.

Parameters

  • fieldName - the field to look for a minimum on. Only number fields are supported.

Returns

if no objects exist or they all have null as the value for the given field, null will be returned. Otherwise the minimum value is returned. When determining the minimum value, objects with null values are ignored.

Throws

public Date minimumDate (
String fieldName
)

Finds the minimum value of a field.

Parameters

  • fieldName - the field name

Returns

if no objects exist or they all have null as the value for the given date field, null will be returned. Otherwise the minimum date is returned. When determining the minimum date, objects with null values are ignored.

Throws

public RealmQuery not ()

Negate condition.

Returns

the query object.

String fieldName,
ObjectId value
)

Not-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
Decimal128 value
)

Not-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

String fieldName,
String value,
Case casing
)

Not-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.
  • casing - how casing is handled. Case.INSENSITIVE works only for the Latin-1 characters.

Returns

the query object.

Throws

String fieldName,
String value
)

Not-equal-to comparison.

Parameters

  • fieldName - the field to compare.
  • value - the value to compare with.

Returns

the query object.

Throws

public RealmQuery or ()

Logical-or two conditions.

Returns

the query object.

public RealmQuery sort (
java.lang.String[] fieldNames,
io.realm.Sort[] sortOrders
)

Sorts the query result by the specific field names in the provided orders. Later fields will only be used if the previous field values are equal.Sorting is currently limited to character sets in 'Latin Basic', 'Latin Supplement', 'Latin Extended A', 'Latin Extended B' (UTF-8 range 0-591). For other character sets, sorting will have no effect.

Parameters

  • fieldNames - an array of field names to sort by.
  • sortOrders - how to sort the field names.

Throws

public RealmQuery sort (
String fieldName1,
Sort sortOrder1,
String fieldName2,
Sort sortOrder2
)

Sorts the query result by the specific field names in the provided orders. fieldName2 is only used in case of equal values in fieldName1 .

Sorting is currently limited to character sets in 'Latin Basic', 'Latin Supplement', 'Latin Extended A', 'Latin Extended B' (UTF-8 range 0-591). For other character sets, sorting will have no effect.

Parameters

  • fieldName1 - first field name
  • sortOrder1 - sort order for first field
  • fieldName2 - second field name
  • sortOrder2 - sort order for second field

Throws

public RealmQuery sort (
String fieldName,
Sort sortOrder
)

Sorts the query result by the specified field name and order.Sorting is currently limited to character sets in 'Latin Basic', 'Latin Supplement', 'Latin Extended A', 'Latin Extended B' (UTF-8 range 0-591). For other character sets, sorting will have no effect.

Parameters

  • fieldName - the field name to sort by.
  • sortOrder - how to sort the results.

Throws

public RealmQuery sort (
String fieldName
)

Sorts the query result by the specific field name in ascending order.Sorting is currently limited to character sets in 'Latin Basic', 'Latin Supplement', 'Latin Extended A', 'Latin Extended B' (UTF-8 range 0-591). For other character sets, sorting will have no effect.

Parameters

  • fieldName - the field name to sort by.

Throws

public Number sum (
String fieldName
)

Calculates the sum of a given field.

Parameters

  • fieldName - the field to sum. Only number fields are supported.

Returns

the sum of fields of the matching objects. If no objects exist or they all have null as the value for the given field, 0 will be returned. When computing the sum, objects with null values are ignored.

Throws

←  Interface RealmObjectSchema.FunctionClass RealmResults →
Give Feedback