title: Realm.io - How to update object?
body: <p>I am using 0.81.1 version of Realm. I have this class:</p>
  
  <pre><code>public class KanjiComp extends RealmObject {
  
      @PrimaryKey
      private String character;
      private String strokes;
      private int frequency;
  
      public String getCharacter() {
          return character;
      }
  
      public void setCharacter(String character) {
          this.character = character;
      }
  
      public String getStrokes() {
          return strokes;
      }
  
      public void setStrokes(String strokes) {
          this.strokes = strokes;
      }
  
      public int getFrequency() {
          return frequency;
      }
  
      public void setFrequency(int frequency) {
          this.frequency = frequency;
      }
  }
  </code></pre>
  
  <p>For the first time, I create object like this:</p>
  
  <pre><code>    KanjiComp realmKanjiComp = realm.createObject(KanjiComp.class);
      realmKanjiComp.setCharacter(cur.getString(cur.getColumnIndex("literal")));
      realmKanjiComp.setStrokes(cur.getString(cur.getColumnIndex("strokes")));
      realmKanjiComp.setFrequency(0);
  </code></pre>
  
  <p>I want to increment frequency value. For this purpose I need method which helps me update frequency.</p>
  
  <p>Realm documentation says this:</p>
  
  <blockquote>
    <p>Using primary keys makes it possible to use the createOrUpdate()
    method, which will look for an existing object with this primary key,
    an update it if it finds one; if none are found, it will create a new
    object instead.</p>
  </blockquote>
  
  <p>But I could not find createOrUpdate() method. All methods to work with JSON.
  <img src="https://i.stack.imgur.com/kFmLM.jpg" alt="enter image description here"></p>
  
  <p>My full code looks like this:</p>
  
  <pre><code>        try {
              KanjiComp realmKanjiComp = realm.createObject(KanjiComp.class);
              character = cur.getString(cur.getColumnIndex("literal"));
              realmKanjiComp.setCharacter(cur.getString(cur.getColumnIndex("literal")));
              realmKanjiComp.setStrokes(cur.getString(cur.getColumnIndex("strokes")));
              realmKanjiComp.setFrequency(0);
          } catch (Exception e) {
              RealmQuery&lt;KanjiComp&gt; query = realm.where(KanjiComp.class);
              query.equalTo("character", character);
              RealmResults&lt;KanjiComp&gt; rKanjiComp = query.findAll();
              KanjiComp oldKanjiComp = rKanjiComp.get(0);
  
              KanjiComp realmKanjiComp = realm.update(KanjiComp.class);//update is underlined
              realmKanjiComp.setCharacter(cur.getString(cur.getColumnIndex("literal")));
              realmKanjiComp.setStrokes(cur.getString(cur.getColumnIndex("strokes")));
              realmKanjiComp.setFrequency(oldKanjiComp.getFrequency()+1);
          }
  </code></pre>
  
  <p>So my question is, how to update value of my object? Is there any way to increment value of my object?</p>