Search code examples
parse-platform

What is the difference between “ParseObject.put()” and “ParseObject.add()”?


I am learning about Parse database when I came across this, please explain it with example

I referred this answer but I couldn't understand the green ticked answer


Solution

  • It would be good if you could specify which Parse SDK you are talking about, but I will consider we are talking about the Android SDK.

    ParseObject.put() can be used to set a value to an object's field:

    ParseObject gameScore = new ParseObject("GameScore");
    gameScore.put("score", 1337);
    gameScore.put("playerName", "Sean Plott");
    gameScore.put("cheatMode", false);
    gameScore.saveInBackground();
    

    ParseObject.add() can be used to add a value to an object's field of type ARRAY:

    gameScore.add("skills", "flying");
    gameScore.add("skills", "kungfu");
    gameScore.saveInBackground();