Docs Menu
Docs Home
/ /
Atlas Device SDKs
/
/

CRUD - Create - Java SDK

On this page

  • About the Examples on this Page
  • Create a New Object

The examples on this page use the data model of a project management app that has two Realm object types: Project and Task. A Project has zero or more Tasks.

See the schema for these two classes, Project and Task, below:

Use realm.createObject() in a transaction to create a persistent instance of a Realm object in a realm. You can then modify the returned object with other field values using accessors and mutators.

The following example demonstrates how to create an object with createObject():

You can also insert objects into a realm from JSON. Realm supports creating objects from String, JSONObject, and InputStream types. Realm ignores any properties present in the JSON that are not defined in the Realm object schema.

The following example demonstrates how to create a single object from JSON with createObjectFromJson() or multiple objects from JSON with createAllFromJson():

← 
 →