Stay organized with collections
Save and categorize content based on your preferences.
publicfinalclassCursorimplementsSerializable
A cursor that represents a position in a query.
To resume a Query at the position defined by a Cursor, the Cursor must
be present in the FetchOptions passed to a PreparedQuery identical to the one it
was created from.
Cursors can be retrieved from PreparedQuery.asQueryResult* functions. A typical use
case would be:
The encoded cursor can then be passed safely in a get or post arg of a web request and on another
request the next batch of results can be retrieved with:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eCursor\u003c/code\u003e class represents a position within a query, enabling the resumption of a query from a specific point.\u003c/p\u003e\n"],["\u003cp\u003eCursors can be obtained from \u003ccode\u003ePreparedQuery.asQueryResult*\u003c/code\u003e functions and are used in \u003ccode\u003eFetchOptions\u003c/code\u003e to define the starting point of a query.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eCursor\u003c/code\u003e objects can be converted into a web-safe string using \u003ccode\u003etoWebSafeString()\u003c/code\u003e, which can later be decoded back into a \u003ccode\u003eCursor\u003c/code\u003e object with \u003ccode\u003efromWebSafeString(String)\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ereverse()\u003c/code\u003e method is now deprecated as it is no longer necessary to call it on cursors.\u003c/p\u003e\n"]]],[],null,["# Class Cursor (2.0.0)\n\n public final class Cursor implements Serializable\n\nA cursor that represents a position in a query.\n\nTo resume a [Query](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.Query(class)) at the position defined by a [Cursor](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.Cursor), the [Cursor](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.Cursor) must\nbe present in the [FetchOptions](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.urlfetch.FetchOptions) passed to a [PreparedQuery](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.PreparedQuery) identical to the one it\nwas created from.\n\nCursors can be retrieved from `PreparedQuery.asQueryResult*` functions. A typical use\ncase would be:\n\u003e\n\u003e\n\u003e Cursor originalCursor = preparedQuery.asQueryResultList(withLimit(20)).getCursor();\n\u003e String encodedCursor = original.toWebSafeString();\n\u003e \nThe encoded cursor can then be passed safely in a get or post arg of a web request and on another\nrequest the next batch of results can be retrieved with:\n\u003e\n\u003e\n\u003e Cursor decodedCursor = Cursor.fromWebSafeString(encodedCursor);\n\u003e List\u003cEntity\u003e nextBatch = preparedQuery.asQueryResultList(withLimit(20).cursor(decoded));\n\u003e \nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e Cursor \n\nImplements\n----------\n\n[Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html) \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Methods\n--------------\n\n### fromWebSafeString(String encodedCursor)\n\n public static Cursor fromWebSafeString(String encodedCursor)\n\nDecodes the given encoded cursor\n\nMethods\n-------\n\n### equals(@Nullable Object obj)\n\n public boolean equals(@Nullable Object obj)\n\n**Overrides** \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)\n\n### hashCode()\n\n public int hashCode()\n\n**Overrides** \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)\n\n### reverse() (deprecated)\n\n public Cursor reverse()\n\n**Deprecated.** *It is no longer necessary to call [#reverse()](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.Cursor#com_google_appengine_api_datastore_Cursor_reverse__) on cursors.*\n\n*A cursor returned by a query may also be used in the query returned by [com.google.appengine.api.datastore.Query#reverse()](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.Query#com_google_appengine_api_datastore_Query_reverse__).*\n\nReturns a cursor identical to `this`.\n\n### toString()\n\n public String toString()\n\n**Overrides** \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)\n\n### toWebSafeString()\n\n public String toWebSafeString()\n\nEncodes the current cursor as a web safe string that can later be decoded by [#fromWebSafeString(String)](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.Cursor#com_google_appengine_api_datastore_Cursor_fromWebSafeString_java_lang_String_)"]]